I’ve tweaked your code by getting rid of flex
on the .form-rows
(obviously you only need to do this on screensizes > 700px as your media query shows).
I’ve then taken off the width
of the label
as it was having no effect when you were using flex
anyway, and then floated both the label
and the input
.
To get a new line to start, you can use clear:left
, on the label
, which essentially means start a new row and ignore everything before that’s floated.
Complete code:
@media only screen and (min-width: 700px) {
.speaker-form,
.speaker-form-header {
width: 600px;
}
.form-row {
/* flex-direction: row;
align-items: flex-start; /* To avoid stretching */
margin-bottom: 20px;
}
.form-row input[type='text'],
.form-row input[type='email'] {
background-color: #FFFFFF;
width: 250px;
height: initial;
float:left;
}
.form-row label {
text-align: right;
width: auto;
margin-top: 7px;
padding-right: 20px;
clear:left;
float:left
}
}
<!DOCTYPE html>
<html lang='en'>
<head>
<meta charset='UTF-8'/>
<title>Speaker Submission</title>
<link rel='stylesheet' href='styles.css'/>
</head>
<body>
<header class='speaker-form-header'>
<h1>Speaker Submission</h1>
<p><em>Want to speak at our fake conference? Fill out
this form.</em></p>
</header>
<form action='' method='get' class='speaker-form'> <!-- The action attribute contains a URL. All the information is sent to that URL. Meanwhile, the method attribute lets you later analyze the info.-->
<div class='form-row'>
<label for='full-name'>Name</label> <!--The label element lets us collect user input. The for and id attribute must always match-->
<input id='full-name' name='full-name' type='text'/> <!--The input element creates a text field, and it can change according to the type of arguments stated later. When the information is returned to the server, it returns with the name stated in the name attribute plus the value entered-->
<label for='email'>Email</label>
<input id='email' name='email' type='email' placeholder='[email protected]'/>
</div>
</form>
</body>
</html>
Working fiddle : https://jsfiddle.net/9rah0516/ (the snippet won’t show properly as you’re limited by screen width – or try running clicking Full Page after running snippet where it will work)