Make an element float to the right inside a div - html

On my product page, there are a number of attributes depending on how many were added to that specific product. It can be from 1 up to 4. The attributes share a common fieldset class name and this is where it gets tricky for me. Basically I'm trying to position 2 of the fieldsets side by side and the rest below them (also side by side). However, I also want them separated and stick to their respective sides within the container. I've managed to make parts of what I said above happen but I have an issue with making the right fieldsets stick to the right side completely. Here's an image description:
Here's the code so far:
https://jsfiddle.net/26za63sh/
HTML:
<div class="container">
<div class="product_attributes clearfix">
<div id="attributes">
<div class="clearfix"></div>
<fieldset class="attribute_fieldset">
<label class="attribute_label" for="group_2">Choose</label>
<div class="attribute_list">
<select name="group_2" id="group_2" class="form-control attribute_select no-print">
<option value="81" selected="selected" title="Option #1">Option #1</option>
<option value="150" title="Option #2">Option #2</option>
</select>
</div>
</fieldset>
<fieldset class="attribute_fieldset">
<label class="attribute_label" for="group_6">Choose</label>
<div class="attribute_list">
<select name="group_6" id="group_6" class="form-control attribute_select no-print">
<option value="31" selected="selected" title="Option #1">Option #1</option>
<option value="56" title="Option #2">Option #2</option>
</select>
</div>
</fieldset>
<fieldset class="attribute_fieldset">
<label class="attribute_label" for="group_5">Choose</label>
<div class="attribute_list">
<select name="group_5" id="group_5" class="form-control attribute_select no-print">
<option value="80" selected="selected" title="Option #1">Option #1</option>
<option value="151" title="Option #2">Option #2</option>
</select>
</div>
</fieldset>
</div>
</div>
</div>
CSS:
.container {
width: 400px;
height: 200px;
background-color: gray;
border: 1px solid #dddddd;
}
fieldset {
padding: 0;
margin: 0;
border: 0;
}
#attributes .attribute_list {
width: 90%;
}
#attributes fieldset {
float: left;
width: 50%;
padding-bottom: 5px;
}
#attributes fieldset:last-child {
float: left;
padding-bottom: 0px;
}
I understand that if I set .attribute_list's width to 100% it will accomplish what I'm trying to do but then the two fieldsets will have no space in the middle. If I instead set a fixed width instead of percentage, then I'll have issues in mobile/tablet view. Any suggestions?

Try this. If you want align items in line and float right.
.attribute-container{display:inline-block;}
.attribute_fieldset:nth-child(odd) .attribute-container{float:right;}
.container {
width: 400px;
height: 200px;
background-color: gray;
border: 1px solid #dddddd;
}
fieldset {
padding: 0;
margin: 0;
border: 0;
}
#attributes .attribute_list {
width: 90%;
}
#attributes fieldset {
float: left;
width: 50%;
padding-bottom: 5px;
}
#attributes fieldset:last-child {
float: left;
padding-bottom: 0px;
}
<div class="container">
<div class="product_attributes clearfix">
<div id="attributes">
<div class="clearfix"></div>
<fieldset class="attribute_fieldset">
<div class="attribute-container">
<label class="attribute_label" for="group_2">Choose 1</label>
<div class="attribute_list">
<select name="group_2" id="group_2" class="form-control attribute_select no-print">
<option value="81" selected="selected" title="Option #1">Option #1</option>
<option value="150" title="Option #2">Option #2</option>
</select>
</div>
</div>
</fieldset>
<fieldset class="attribute_fieldset">
<div class="attribute-container">
<label class="attribute_label" for="group_6">Choose 2</label>
<div class="attribute_list">
<select name="group_6" id="group_6" class="form-control attribute_select no-print">
<option value="31" selected="selected" title="Option #1">Option #1</option>
<option value="56" title="Option #2">Option #2</option>
</select>
</div>
</div>
</fieldset>
<fieldset class="attribute_fieldset">
<div class="attribute-container">
<label class="attribute_label" for="group_5">Choose 3</label>
<div class="attribute_list">
<select name="group_5" id="group_5" class="form-control attribute_select no-print">
<option value="80" selected="selected" title="Option #1">Option #1</option>
<option value="151" title="Option #2">Option #2</option>
</select>
</div>
</div>
</fieldset>
</div>
</div>
</div>

The problem is the elements in fieldset all float to left.
Add this to float the inner elements of odd fieldsets to right:
#attributes fieldset:nth-child(odd) * {
float: right;
}
JSFiddle: https://jsfiddle.net/er_han/Lprh9zqf/

Related

Why do my field-set containers overflow at mobile-view, but not at larger screen sizes?

I'm creating a mobile-first responsive website using forms. This is the desired mockup I need to create after 769px. https://ibb.co/LQ0Gwt7. Here is the desired mockup for 769px and below: https://ibb.co/7tbDShb
But why is that before 769px, the contents of my fieldset containers spill out?Whats causing this to happen? I put red borders around certain elements for clarity sake.
Take a look here: https://ibb.co/1J9n8pW
Here`s my CSS and HTML code:
* {
box-sizing: border-box;
}
body {
background: seashell;
font-family: 'Merriweather', serif;
}
.header-content {
text-align: center;
background: #29405a;
color: white;
border: 1px solid #29405a;
}
.signup {
text-align: center;
border-bottom: 2px #29405a dashed;
margin: 0 auto;
width: 90%;
}
.form {
margin: 10px auto;
width: 70%;
background: #feffff;
padding: 30px;
border-radius: 10px;
border: 1px red solid;
}
.field {
padding: 20px;
margin: 0 auto;
border: 3px red solid;
}
/*input styles*/
input[type="text"],
input[type="email"],
input[type="tel"],
textarea,
select {
background: #e8eeef;
box-shadow: 0 1px 0 rgba(0, 0, 0, 0.03) inset;
border: none;
border-radius: 5px;
padding: 12px 0;
}
button[type="submit"] {
background: #52bab3;
color: #FFF;
padding: 10px 30px;
border: none;
border-radius: 5px;
cursor: pointer;
}
.news-input {
margin-bottom: 20px;
}
.news-input label {
margin-left: 10px;
}
.contact-input {
margin: 20px auto;
border: 1px red solid;
display: flex;
flex-wrap: wrap;
flex-direction: column;
}
.label {
margin-bottom: 10px;
}
.textarea {
display: flex;
flex-direction: column;
}
.button {
display: flex;
flex-direction: column;
}
.extra-info {
text-align: center;
}
#media (min-width: 768px) {
.contact-input {
display: flex;
flex-direction: row;
}
.label,
.input {
flex: 1;
}
.input {
flex: 3;
}
.zip-input,
.zip-label {
flex: 0;
flex-basis: 25%;
}
}
<!DOCTYPE html>
<html lang='en'>
<head>
<meta charset='UTF-8' />
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Registration Form</title>
<link rel="stylesheet" href="css/normalize.css">
<link rel="stylesheet" href="css/styles.css">
<link href="https://fonts.googleapis.com/css?family=Merriweather&display=swap" rel="stylesheet">
</head>
<body>
<header>
<div class="header-content">
<h1>The Code Review</h1>
</div>
</header>
<div class="signup">
<h2>Sign up for our newsletter</h2>
<p>Get the latest news on how your code is doing right in your inbox</p>
</div>
<form action="index.html" get="post" class="form">
<fieldset class="field">
<legend>Contact Information</legend>
<div class="contact-input">
<label class="label" for="name">Name</label>
<input class="input" type="text" id="name" name="user_name">
</div>
<div class="contact-input">
<label class="label" for="mail">Email Address</label>
<input class="input" type="email" id="mail" name="user_email">
</div>
<div class="contact-input">
<label class="label" for="phone-number">Phone Number</label>
<input class="input" type="tel" id="phone-number" name="user_phone">
</div>
<div class="contact-input">
<label class="label" for="street">Street Address</label>
<input class="input" type="text" id="street" name="user_street">
</div>
<div class="contact-input">
<label class="label" for="city">City</label>
<input class="input" type="text" id="city" name="user_city">
</div>
<div class="contact-input">
<label class="label" for="state">State</label>
<select class="input" id="state" name="user_state">
<option value="AL">Alabama</option>
<option value="AK">Alaska</option>
<option value="AZ">Arizona</option>
<option value="AR">Arkansas</option>
<option value="CA">California</option>
<option value="CO">Colorado</option>
<option value="CT">Connecticut</option>
<option value="DE">Delaware</option>
<option value="DC">District Of Columbia</option>
<option value="FL">Florida</option>
<option value="GA">Georgia</option>
<option value="HI">Hawaii</option>
<option value="ID">Idaho</option>
<option value="IL">Illinois</option>
<option value="IN">Indiana</option>
<option value="IA">Iowa</option>
<option value="KS">Kansas</option>
<option value="KY">Kentucky</option>
<option value="LA">Louisiana</option>
<option value="ME">Maine</option>
<option value="MD">Maryland</option>
<option value="MA">Massachusetts</option>
<option value="MI">Michigan</option>
<option value="MN">Minnesota</option>
<option value="MS">Mississippi</option>
<option value="MO">Missouri</option>
<option value="MT">Montana</option>
<option value="NE">Nebraska</option>
<option value="NV">Nevada</option>
<option value="NH">New Hampshire</option>
<option value="NJ">New Jersey</option>
<option value="NM">New Mexico</option>
<option value="NY">New York</option>
<option value="NC">North Carolina</option>
<option value="ND">North Dakota</option>
<option value="OH">Ohio</option>
<option value="OK">Oklahoma</option>
<option value="OR">Oregon</option>
<option value="PA">Pennsylvania</option>
<option value="RI">Rhode Island</option>
<option value="SC">South Carolina</option>
<option value="SD">South Dakota</option>
<option value="TN">Tennessee</option>
<option value="TX">Texas</option>
<option value="UT">Utah</option>
<option value="VT">Vermont</option>
<option value="VA">Virginia</option>
<option value="WA">Washington</option>
<option value="WV">West Virginia</option>
<option value="WI">Wisconsin</option>
<option value="WY">Wyoming</option>
</select>
</div>
<div class="contact-input zip">
<label class="label zip-label" for="zip">Zip Code</label>
<input class="input zip-input" type="text" id="zip" name="user_zipcode">
</div>
</fieldset>
<fieldset class="field">
<legend>Newsletter</legend>
<p>Select the newspaper you'd like to recieve:</p>
<div class="news-input">
<input type="checkbox" id="html-news" name="user_htm-news" checked></input>
<label for="html-news">HTML News</label>
</div>
<div class="news-input">
<input type="checkbox" id="css-news" name="user_css-news">
<label for="css-news">CSS News</label>
</div>
<div class="news-input">
<input type="checkbox" id="javascript-news" name="user_javascript-news">
<label for="javascript-news">Javascript News</label>
</div>
<p>Newsletter Format</p>
<div class="news-input">
<input type="radio" id="html" name="user_newsletter-format" checked>
<label for="html">HTML</label>
</div>
<div class="news-input">
<input type="radio" id="css-news" name="user_newsletter-format">
<label for="css-news">CSS News</label>
</div>
<p>Other topics you'd like to hear about</p>
<div class="textarea">
<textarea id="topics" name="user_topics"></textarea>
</div>
</fieldset>
<div class="button">
<button type="submit">Sign Up</button>
</div>
<div class="extra-info">
<p>Copyright the Code Review</p>
</div>
</form>
</body>
</html>
On small screens you have to set
.form {
width: 100%;
}
otherwise the bigger components will overflow your too small .form div.
* {
box-sizing: border-box;
}
body {
background: seashell;
font-family: 'Merriweather', serif;
}
.header-content {
text-align: center;
background: #29405a;
color: white;
border: 1px solid #29405a;
}
.signup {
text-align: center;
border-bottom: 2px #29405a dashed;
margin: 0 auto;
width: 90%;
}
.form {
margin: 10px auto;
width: 100%; /* SET TO 100% */
background: #feffff;
padding: 30px;
border-radius: 10px;
border: 1px red solid;
}
.field {
padding: 20px;
margin: 0 auto;
border: 3px red solid;
}
/*input styles*/
input[type="text"],
input[type="email"],
input[type="tel"],
textarea,
select {
background: #e8eeef;
box-shadow: 0 1px 0 rgba(0, 0, 0, 0.03) inset;
border: none;
border-radius: 5px;
padding: 12px 0;
}
button[type="submit"] {
background: #52bab3;
color: #FFF;
padding: 10px 30px;
border: none;
border-radius: 5px;
cursor: pointer;
}
.news-input {
margin-bottom: 20px;
}
.news-input label {
margin-left: 10px;
}
.contact-input {
margin: 20px auto;
border: 1px red solid;
display: flex;
flex-wrap: wrap;
flex-direction: column;
}
.label {
margin-bottom: 10px;
}
.textarea {
display: flex;
flex-direction: column;
}
.button {
display: flex;
flex-direction: column;
}
.extra-info {
text-align: center;
}
#media (min-width: 768px) {
.form{
width: 70%;
}
.contact-input {
display: flex;
flex-direction: row;
}
.label,
.input {
flex: 1;
}
.input {
flex: 3;
}
.zip-input,
.zip-label {
flex: 0;
flex-basis: 25%;
}
}
<!DOCTYPE html>
<html lang='en'>
<head>
<meta charset='UTF-8' />
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Registration Form</title>
<link rel="stylesheet" href="css/normalize.css">
<link rel="stylesheet" href="css/styles.css">
<link href="https://fonts.googleapis.com/css?family=Merriweather&display=swap" rel="stylesheet">
</head>
<body>
<header>
<div class="header-content">
<h1>The Code Review</h1>
</div>
</header>
<div class="signup">
<h2>Sign up for our newsletter</h2>
<p>Get the latest news on how your code is doing right in your inbox</p>
</div>
<form action="index.html" get="post" class="form form_setter">
<fieldset class="field">
<legend>Contact Information</legend>
<div class="contact-input">
<label class="label" for="name">Name</label>
<input class="input" type="text" id="name" name="user_name">
</div>
<div class="contact-input">
<label class="label" for="mail">Email Address</label>
<input class="input" type="email" id="mail" name="user_email">
</div>
<div class="contact-input">
<label class="label" for="phone-number">Phone Number</label>
<input class="input" type="tel" id="phone-number" name="user_phone">
</div>
<div class="contact-input">
<label class="label" for="street">Street Address</label>
<input class="input" type="text" id="street" name="user_street">
</div>
<div class="contact-input">
<label class="label" for="city">City</label>
<input class="input" type="text" id="city" name="user_city">
</div>
<div class="contact-input">
<label class="label" for="state">State</label>
<select class="input" id="state" name="user_state">
<option value="AL">Alabama</option>
<option value="AK">Alaska</option>
<option value="AZ">Arizona</option>
<option value="AR">Arkansas</option>
<option value="CA">California</option>
<option value="CO">Colorado</option>
<option value="CT">Connecticut</option>
<option value="DE">Delaware</option>
<option value="DC">District Of Columbia</option>
<option value="FL">Florida</option>
<option value="GA">Georgia</option>
<option value="HI">Hawaii</option>
<option value="ID">Idaho</option>
<option value="IL">Illinois</option>
<option value="IN">Indiana</option>
<option value="IA">Iowa</option>
<option value="KS">Kansas</option>
<option value="KY">Kentucky</option>
<option value="LA">Louisiana</option>
<option value="ME">Maine</option>
<option value="MD">Maryland</option>
<option value="MA">Massachusetts</option>
<option value="MI">Michigan</option>
<option value="MN">Minnesota</option>
<option value="MS">Mississippi</option>
<option value="MO">Missouri</option>
<option value="MT">Montana</option>
<option value="NE">Nebraska</option>
<option value="NV">Nevada</option>
<option value="NH">New Hampshire</option>
<option value="NJ">New Jersey</option>
<option value="NM">New Mexico</option>
<option value="NY">New York</option>
<option value="NC">North Carolina</option>
<option value="ND">North Dakota</option>
<option value="OH">Ohio</option>
<option value="OK">Oklahoma</option>
<option value="OR">Oregon</option>
<option value="PA">Pennsylvania</option>
<option value="RI">Rhode Island</option>
<option value="SC">South Carolina</option>
<option value="SD">South Dakota</option>
<option value="TN">Tennessee</option>
<option value="TX">Texas</option>
<option value="UT">Utah</option>
<option value="VT">Vermont</option>
<option value="VA">Virginia</option>
<option value="WA">Washington</option>
<option value="WV">West Virginia</option>
<option value="WI">Wisconsin</option>
<option value="WY">Wyoming</option>
</select>
</div>
<div class="contact-input zip">
<label class="label zip-label" for="zip">Zip Code</label>
<input class="input zip-input" type="text" id="zip" name="user_zipcode">
</div>
</fieldset>
<fieldset class="field">
<legend>Newsletter</legend>
<p>Select the newspaper you'd like to recieve:</p>
<div class="news-input">
<input type="checkbox" id="html-news" name="user_htm-news" checked></input>
<label for="html-news">HTML News</label>
</div>
<div class="news-input">
<input type="checkbox" id="css-news" name="user_css-news">
<label for="css-news">CSS News</label>
</div>
<div class="news-input">
<input type="checkbox" id="javascript-news" name="user_javascript-news">
<label for="javascript-news">Javascript News</label>
</div>
<p>Newsletter Format</p>
<div class="news-input">
<input type="radio" id="html" name="user_newsletter-format" checked>
<label for="html">HTML</label>
</div>
<div class="news-input">
<input type="radio" id="css-news" name="user_newsletter-format">
<label for="css-news">CSS News</label>
</div>
<p>Other topics you'd like to hear about</p>
<div class="textarea">
<textarea id="topics" name="user_topics"></textarea>
</div>
</fieldset>
<div class="button">
<button type="submit">Sign Up</button>
</div>
<div class="extra-info">
<p>Copyright the Code Review</p>
</div>
</form>
</body>
</html>
Form inputs have a default width that the user agent (browser) applies unless you override it.
The size IDL attribute is limited to only non-negative numbers greater than zero and has a default value of 20.
The container for your form inputs is 70% the width of the viewport, once the viewport is small enough, 70% becomes less than the default width of the form inputs. Thus the overflow.
At larger viewport sizes you're using flexbox properties which causes the inputs to stretch a particular width of their containing element.
Apply width: 100%; to your form inputs.
input[type="text"],
input[type="email"],
input[type="tel"],
textarea,
select {
width: 100%;
background: #e8eeef;
box-shadow: 0 1px 0 rgba(0, 0, 0, 0.03) inset;
border: none;
border-radius: 5px;
padding: 12px 0;
}
This would be your best approach, no need for media query:
.form {
width: 100%;
display: block;
margin-left: auto;
margin-right: auto;
max-width: 1024px; //insert your prefer value here;
}

How do I shorten a flex item in a form without breaking the layout?

I'm creating a mobile-first responsive website using forms. This is the desired mockup I need to create after 769px.
Under contact information, How do I shorten the zip input as they have it, while also keeping it in the same place using flexbox?
Is it not possible to do this using solely flexbox properties, or would I have to do something else such as apply a position property to it?
I set the flex-grow property for the rest of the containers properly, but I know I have to do something for the last flex container. Below is my HTML and CSS code for this project.
* {
box-sizing: border-box;
}
body {
background: seashell;
font-family: 'Merriweather', serif;
}
.header-content {
text-align: center;
background: #29405a;
color: white;
border: 1px solid #29405a;
}
.signup {
text-align: center;
border-bottom: 2px #29405a dashed;
margin: 0 auto;
width: 90%;
}
form {
margin: 10px auto;
width: 90%;
background: #feffff;
padding: 20px;
border-radius: 10px;
border: 1px red solid;
}
.field {
padding: 20px;
margin: 0 auto;
border: 3px red solid;
}
/*input styles*/
input[type="text"],
input[type="email"],
input[type="tel"],
textarea,
select {
background: #e8eeef;
box-shadow: 0 1px 0 rgba(0, 0, 0, 0.03) inset;
border: none;
border-radius: 5px;
padding: 12px 0;
}
button[type="submit"] {
background: #52bab3;
color: #FFF;
padding: 10px 30px;
border: none;
border-radius: 5px;
cursor: pointer;
}
.news-input {
margin-bottom: 20px;
}
.news-input label {
margin-left: 10px;
}
.contact-input {
margin: 20px auto;
border: 1px red solid;
display: flex;
flex-wrap: wrap;
flex-direction: column;
}
.label {
margin-bottom: 10px;
}
#media (min-width: 768px) {
.contact-input {
display: flex;
flex-direction: row;
}
.label,
.input {
flex: 1;
}
.input {
flex: 3;
}
}
<header>
<div class="header-content">
<h1>The Code Review</h1>
</div>
</header>
<div class="signup">
<h2>Sign up for our newsletter</h2>
<p>Get the latest news on how your code is doing right in your inbox</p>
</div>
<form action="index.html" get="post" class="registration-form">
<fieldset class="first field">
<legend>Contact Information</legend>
<div class="contact-input">
<label class="label" for="name">Name</label>
<input class="input" type="text" id="name" name="user_name">
</div>
<div class="contact-input">
<label class="label" for="mail">Email Address</label>
<input class="input" type="email" id="mail" name="user_email">
</div>
<div class="contact-input">
<label class="label" for="phone-number">Phone Number</label>
<input class="input" type="tel" id="phone-number" name="user_phone">
</div>
<div class="contact-input">
<label class="label" for="street">Street Address</label>
<input class="input" type="text" id="street" name="user_street">
</div>
<div class="contact-input">
<label class="label" for="city">City</label>
<input class="input" type="text" id="city" name="user_city">
</div>
<div class="contact-input">
<label class="label" for="state">State</label>
<select class="input" id="state" name="user_state">
<option value="AL">Alabama</option>
<option value="AK">Alaska</option>
<option value="AZ">Arizona</option>
<option value="AR">Arkansas</option>
<option value="CA">California</option>
<option value="CO">Colorado</option>
<option value="CT">Connecticut</option>
<option value="DE">Delaware</option>
<option value="DC">District Of Columbia</option>
<option value="FL">Florida</option>
<option value="GA">Georgia</option>
<option value="HI">Hawaii</option>
<option value="ID">Idaho</option>
<option value="IL">Illinois</option>
<option value="IN">Indiana</option>
<option value="IA">Iowa</option>
<option value="KS">Kansas</option>
<option value="KY">Kentucky</option>
<option value="LA">Louisiana</option>
<option value="ME">Maine</option>
<option value="MD">Maryland</option>
<option value="MA">Massachusetts</option>
<option value="MI">Michigan</option>
<option value="MN">Minnesota</option>
<option value="MS">Mississippi</option>
<option value="MO">Missouri</option>
<option value="MT">Montana</option>
<option value="NE">Nebraska</option>
<option value="NV">Nevada</option>
<option value="NH">New Hampshire</option>
<option value="NJ">New Jersey</option>
<option value="NM">New Mexico</option>
<option value="NY">New York</option>
<option value="NC">North Carolina</option>
<option value="ND">North Dakota</option>
<option value="OH">Ohio</option>
<option value="OK">Oklahoma</option>
<option value="OR">Oregon</option>
<option value="PA">Pennsylvania</option>
<option value="RI">Rhode Island</option>
<option value="SC">South Carolina</option>
<option value="SD">South Dakota</option>
<option value="TN">Tennessee</option>
<option value="TX">Texas</option>
<option value="UT">Utah</option>
<option value="VT">Vermont</option>
<option value="VA">Virginia</option>
<option value="WA">Washington</option>
<option value="WV">West Virginia</option>
<option value="WI">Wisconsin</option>
<option value="WY">Wyoming</option>
</select>
</div>
<div class="contact-input zip">
<label class="label zip-label" for="zip">Zip Code</label>
<input class="input zip-input" type="text" id="zip" name="user_zipcode">
</div>
</fieldset>
<fieldset class="second field">
<legend>Newsletter</legend>
<p>Select the newspaper you'd like to recieve:</p>
<div class="news-input">
<input type="checkbox" id="html-news" name="user_htm-news" checked></input>
<label for="html-news">HTML News</label>
</div>
<div class="news-input">
<input type="checkbox" id="css-news" name="user_css-news">
<label for="css-news">CSS News</label>
</div>
<div class="news-input">
<input type="checkbox" id="javascript-news" name="user_javascript-news">
<label for="javascript-news">Javascript News</label>
</div>
<p>Newsletter Format</p>
<div class="news-input">
<input type="radio" id="html" name="user_newsletter-format" checked>
<label for="html">HTML</label>
</div>
<div class="news-input">
<input type="radio" id="css-news" name="user_newsletter-format">
<label for="css-news">CSS News</label>
</div>
<p>Other topics you'd like to hear about</p>
<textarea id="topics" name="user_topics"></textarea>
</fieldset>
<button type="submit">Sign Up</button>
</form>
The fundamental problem is your use of flex-grow.
.label,
.input {
flex: 1; /* flex-grow: 1, flex-shrink: 0, flex-basis: 0 */
}
.input {
flex: 3;
}
By activating flex-grow on both elements in the row, each of them will always try to consume all free space in the row. So there's no way an input (or a label) can be shorter, because as long as there is free space, flex-grow tells it to occupy that space.
I think you may be better off using flex-basis. With this property you have more control over the sizing of flex items.
Make this adjustment to your code:
#media (min-width: 768px) {
.contact-input {
display: flex;
flex-direction: row;
}
.label,
.input {
flex-basis: 25%;
}
.input {
flex-basis: 75%;
}
.zip-input {
flex-basis: 25%;
}
}
* {
box-sizing: border-box;
}
body {
background: seashell;
font-family: 'Merriweather', serif;
}
.header-content {
text-align: center;
background: #29405a;
color: white;
border: 1px solid #29405a;
}
.signup {
text-align: center;
border-bottom: 2px #29405a dashed;
margin: 0 auto;
width: 90%;
}
form {
margin: 10px auto;
width: 90%;
background: #feffff;
padding: 20px;
border-radius: 10px;
border: 1px red solid;
}
.field {
padding: 20px;
margin: 0 auto;
border: 3px red solid;
}
/*input styles*/
input[type="text"],
input[type="email"],
input[type="tel"],
textarea,
select {
background: #e8eeef;
box-shadow: 0 1px 0 rgba(0, 0, 0, 0.03) inset;
border: none;
border-radius: 5px;
padding: 12px 0;
}
button[type="submit"] {
background: #52bab3;
color: #FFF;
padding: 10px 30px;
border: none;
border-radius: 5px;
cursor: pointer;
}
.news-input {
margin-bottom: 20px;
}
.news-input label {
margin-left: 10px;
}
.contact-input {
margin: 20px auto;
border: 1px red solid;
display: flex;
flex-wrap: wrap;
flex-direction: column;
}
.label {
margin-bottom: 10px;
}
#media (min-width: 768px) {
.contact-input {
display: flex;
flex-direction: row;
}
.label,
.input {
flex-basis: 25%;
}
.input {
flex-basis: 75%;
}
.zip-input {
flex-basis: 25%;
}
}
<header>
<div class="header-content">
<h1>The Code Review</h1>
</div>
</header>
<div class="signup">
<h2>Sign up for our newsletter</h2>
<p>Get the latest news on how your code is doing right in your inbox</p>
</div>
<form action="index.html" get="post" class="registration-form">
<fieldset class="first field">
<legend>Contact Information</legend>
<div class="contact-input">
<label class="label" for="name">Name</label>
<input class="input" type="text" id="name" name="user_name">
</div>
<div class="contact-input">
<label class="label" for="mail">Email Address</label>
<input class="input" type="email" id="mail" name="user_email">
</div>
<div class="contact-input">
<label class="label" for="phone-number">Phone Number</label>
<input class="input" type="tel" id="phone-number" name="user_phone">
</div>
<div class="contact-input">
<label class="label" for="street">Street Address</label>
<input class="input" type="text" id="street" name="user_street">
</div>
<div class="contact-input">
<label class="label" for="city">City</label>
<input class="input" type="text" id="city" name="user_city">
</div>
<div class="contact-input">
<label class="label" for="state">State</label>
<select class="input" id="state" name="user_state">
<option value="AL">Alabama</option>
<option value="AK">Alaska</option>
<option value="AZ">Arizona</option>
<option value="AR">Arkansas</option>
<option value="CA">California</option>
<option value="CO">Colorado</option>
<option value="CT">Connecticut</option>
<option value="DE">Delaware</option>
<option value="DC">District Of Columbia</option>
<option value="FL">Florida</option>
<option value="GA">Georgia</option>
<option value="HI">Hawaii</option>
<option value="ID">Idaho</option>
<option value="IL">Illinois</option>
<option value="IN">Indiana</option>
<option value="IA">Iowa</option>
<option value="KS">Kansas</option>
<option value="KY">Kentucky</option>
<option value="LA">Louisiana</option>
<option value="ME">Maine</option>
<option value="MD">Maryland</option>
<option value="MA">Massachusetts</option>
<option value="MI">Michigan</option>
<option value="MN">Minnesota</option>
<option value="MS">Mississippi</option>
<option value="MO">Missouri</option>
<option value="MT">Montana</option>
<option value="NE">Nebraska</option>
<option value="NV">Nevada</option>
<option value="NH">New Hampshire</option>
<option value="NJ">New Jersey</option>
<option value="NM">New Mexico</option>
<option value="NY">New York</option>
<option value="NC">North Carolina</option>
<option value="ND">North Dakota</option>
<option value="OH">Ohio</option>
<option value="OK">Oklahoma</option>
<option value="OR">Oregon</option>
<option value="PA">Pennsylvania</option>
<option value="RI">Rhode Island</option>
<option value="SC">South Carolina</option>
<option value="SD">South Dakota</option>
<option value="TN">Tennessee</option>
<option value="TX">Texas</option>
<option value="UT">Utah</option>
<option value="VT">Vermont</option>
<option value="VA">Virginia</option>
<option value="WA">Washington</option>
<option value="WV">West Virginia</option>
<option value="WI">Wisconsin</option>
<option value="WY">Wyoming</option>
</select>
</div>
<div class="contact-input zip">
<label class="label zip-label" for="zip">Zip Code</label>
<input class="input zip-input" type="text" id="zip" name="user_zipcode">
</div>
</fieldset>
<fieldset class="second field">
<legend>Newsletter</legend>
<p>Select the newspaper you'd like to recieve:</p>
<div class="news-input">
<input type="checkbox" id="html-news" name="user_htm-news" checked></input>
<label for="html-news">HTML News</label>
</div>
<div class="news-input">
<input type="checkbox" id="css-news" name="user_css-news">
<label for="css-news">CSS News</label>
</div>
<div class="news-input">
<input type="checkbox" id="javascript-news" name="user_javascript-news">
<label for="javascript-news">Javascript News</label>
</div>
<p>Newsletter Format</p>
<div class="news-input">
<input type="radio" id="html" name="user_newsletter-format" checked>
<label for="html">HTML</label>
</div>
<div class="news-input">
<input type="radio" id="css-news" name="user_newsletter-format">
<label for="css-news">CSS News</label>
</div>
<p>Other topics you'd like to hear about</p>
<textarea id="topics" name="user_topics"></textarea>
</fieldset>
<button type="submit">Sign Up</button>
</form>

Placing DIV in form, can't set minimum width and height

I have the following html snippet:
<form name="foo">
<fieldset>
<legend>Legend Here</legend>
<label for="the_date">Date: </label><input type="text" name="the_date" id="the_date">
<select class="show_when_needed" id="event_state">
<option value="-1" selected="selected">N/A</option>
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
<option value="4">Four</option>
<option value="5">Five</option>
<option value="6">Six</option>
</select>
<div class="foobar" style="display: inline; border: 1px black; min-width: 20px; min-height: 15px; background: blue;"></div>
<button type="button" name="go_next" id="go_next">Go!</button>
</fieldset>
<hr />
<button type="button" id="save_object">Save Object</button>
</form>
I am trying to have the div show inline, and set a minimum width (to force it to show on screen).
The HTML above is not achieving that goal. How do I correct it so that the div appears alongside the select option control?
[[Additional Info]]
I have tried this on the latest versions of FF and Chrome - both fail to display correctly.
You need to give the element a display: inline-block, you can't set width or height of an inline element because it behaves just like a <span> or a <strong> would, taking only the space it needs.
Take a look at this updated snippet with display: inline-block
change from display: inline; to display: block;.
<form name="foo">
<fieldset>
<legend>Legend Here</legend>
<label for="the_date">Date: </label><input type="text" name="the_date" id="the_date">
<select class="show_when_needed" id="event_state">
<option value="-1" selected="selected">N/A</option>
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
<option value="4">Four</option>
<option value="5">Five</option>
<option value="6">Six</option>
</select>
<div class="foobar" style="display: block; border: 1px black; min-width: 20px; min-height: 15px; background: blue;"></div>
<button type="button" name="go_next" id="go_next">Go!</button>
</fieldset>
<hr />
<button type="button" id="save_object">Save Object</button>
</form>

How to keep divs from overlapping/moving/making my page look ugly when resizing width and/or height of browser window

So I'm trying to be able to keep everything where it is even on a a window re size.. an example of what I wish for is similar to face book's registration page (or any page on facebook for that matter... everything gets hidden behind the browser as i minimize its width). I've included two links one a jfiddle and second an actual test page:
https://jsfiddle.net/0nskvmjc/
http://sushionfir3.byethost7.com/test/register.php
here's the html for my own registration page
<!--background image-->
<style type="text/css">
body {
background-image: url(bg/bg.jpg);
background-size: cover;
}
</style>
<!---->
<body>
<!--top green transparent bar-->
<nav class="bar"></nav>
<div class="logo">
<img src="img/logo.png" height=90px>
</div>
<br />
<div class="login">Log in</div>
<div class="signin">
<form class="pure-form" action="#" method="post">
<input class="input" type="text" placeholder="Email">
<input class="input" type="password" placeholder="Password">
<button type="submit" class="button-sign pure-button">Sign in</button>
</form>
<!---->
<!--registration form start-->
<div id="reg_border"></div>
<div class="reg_form">
<h2 id="register_right">Registration is free and easy!</h2>
<div class="form_inputs">
<form class="pure-form" action="#" method="POST">
<input class="input" type="text" name="firstname" placeholder="First name" />
<input class="input" type="text" name="lastname" placeholder="Last name" /><br />
<input class="input" type="email" name="email" placeholder="Email" size="49" /><br />
<div class="space">
<input class="input" type="text" name="remail" placeholder="Please re-enter your Email" size="49" /><br />
</div>
<div class="space">
<input class="input" type="password" name="npassword" placeholder="New password" size="49" />
</div>
<p class="birthdate">Date of birth</p>
<div class="birthday_options">
<select class="months">
<option value="jan">Jan</option>
<option value="feb">Feb</option>
<option value="mar">Mar</option>
<option value="apr">Apr</option>
<option value="may">May</option>
<option value="jun">Jun</option>
<option value="jul">Jul</option>
<option value="aug">Aug</option>
<option value="sep">Sep</option>
<option value="oct">Oct</option>
<option value="nov">Nov</option>
<option value="dec">Dec</option>
</select>
<select class="days">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
<option value="31">31</option>
</select>
<input class="input" type="text" name="year" placeholder="mm/dd/yyyy" size="10" />
</div><!--birthdaymonths-->
<p class="sex">Gender</p>
<div class="genders">
<input type="radio" name="gender" value="1">Male</input>
<input type="radio" name="gender" value="2">Female</input>
</div>
<button id="signup" type="submit" class="button-sign pure-button">Sign up!</button>
</form>
</div><!--form_inputs-->
</div><!--reg_form-->
</body>
and here's the css for it
.bar {
width: 100%;
height: 90px;
background-color: rgba(0,160,135,0.4);
}
.logo {
margin-top: -88px;
padding-left: 50px;
}
.login {
text-align: right;
margin-top: -100px;
margin-right: 486px;
color: white;
}
.signin {
text-align: right;
padding-right: 50px;
padding-top: 5px
}
#reg_border {
background: rgba(0,160,135,0.4);
width: 32%;
height: 70%;
margin: 6% 1% 3% auto;
-webkit-border-radius: 70px;
-moz-border-radius: 70px;
-o-border-radius: 70px;
}
.reg_form {
text-align: right;
padding-right: 24px;
line-height: 48px;
margin-top: -525px;
}
.input {
line-height: 20px
}
#register_right {
padding-right: 29px;
padding-top: 30px
}
.birthdate {
margin: auto 310px auto 100px;
}
.birthday_options {
margin: -10px 125px auto 100px;
}
.sex {
margin: -5px 345px auto 100px;
}
.genders {
margin: -20px 265px auto auto;
}
.space {
margin-top: 4px
}
#signup {
width: 13em;
margin: 2px 95px auto auto
}
Thank you in advance. I've tried looking up these questions but none of the answers on other people's questions seem to work for me.. maybe the issue is within what I've already coded and adding extra bits of code isn't going to help or MAYBE it is, I'm not sure haha. Thank you again.
I GOT IT! For me, adding a min and max width of 1366px did the trick!
<style type="text/css">
body, html {
background-image: url(bg/bg.jpg);
background-size: cover;
width: 100%;
height: 100%;
min-width: 1366px;
margin: auto auto;
max-width: 1366px;
}
</style>
I'm somewhat satisfied with its current result, however, still open for a better way :)

How do I make this search form appear correctly on IE6 - IE8?

I'm working on an app and part of the project requirements is that the entire site be compatible with IE6 - IE8. So far, the rest of the website looks good on older browsers except for this search form I created.
This is what it looks like on modern browsers, and is what it's supposed to look like in general: ,
...but this is what it looks like on IE6: .
Does anyone have some experience with trying to make table-less layouts work on older browsers, or has run into a similar issue in the past? Basically I have containers holding each label / input, and need them to display next to each other in three's per row, with the label and input next to each other ass seen on the first image.
Below is the code regarding these elements.
EDIT: I added a few more things to both the html and css for easier deployment on your own computers.
Thanks for any help you can provide!
HTML
<div class="mid">
<h2>Search and filter by:</h2>
<!-- 1st Row Starts -->
<form action="" method="post" id="main-search-form"> <!-- containing form for search -->
<div id="search-container" align="center">
<div class="search" align="center">
<form>
<label>Keywords</label>
<input type="text" name="keywords" value="" id="keywords" placeholder="enter search terms here...">
</form>
</div>
<div class="search" align="center">
<label>Category</label>
<select>
<option value="" disabled selected>Select Category</option>
<option value="">Category 1</option>
<option value="">Category 2</option>
<option value="">Category 3</option>
<option value="">Category 4</option>
<option value="">Category 5</option>
</select>
</div>
<div class="search" align="center">
<label>Service</label>
<select>
<option value="" disabled selected>Select Service</option>
<option value="food">Food and Nutrition Support</option>
<option value="shelter">Shelter and Care</option>
<option value="protection">Protection</option>
<option value="healthcare">Healthcare</option>
<option value="pyschosocial">Psychosocial Support Services</option>
<option value="education">Formal and informal education</option>
<option value="legal">Legal Services</option>
<option value="other">Other Services</option>
</select>
</div>
</div> <!-- //.search-container -->
<!-- // 1st Row -->
<!-- 2nd Row Starts -->
<div id="search-container" align="center">
<div class="search" align="center">
<label>Age</label>
<select>
<option value="" disabled selected>Select Age</option>
<option value="">Age 1-3</option>
<option value="">Age 4-10</option>
<option value="">Age 11-14</option>
<option value="">Age 15-18</option>
</select>
</div>
<div class="search" align="center">
<label>Gender</label>
<select>
<option value="" disabled selected>Select Gender</option>
<option value="male">Male</option>
<option value="female">Female</option>
</select>
</div>
<div class="search" align="center">
<label>Region</label>
<select>
<option value="" disabled selected>Select Region</option>
<option value="">Category 1</option>
<option value="">Category 2</option>
<option value="">Category 3</option>
<option value="">Category 4</option>
<option value="">Category 5</option>
</select>
</div>
</div><!-- //.search-container -->
<!-- // 2nd Row -->
<!-- 3rd Row Starts Here -->
<div class="search-container" align="center">
<div class="search" align="center">
<form class="checkbox">
<label>Day</label>
<input type="checkbox" name="monday" value="Monday">M
<input type="checkbox" name="tuesday" value="Tuesday">T
<input type="checkbox" name="wednesday" value="Wednesday">W
<input type="checkbox" name="thursday" value="Thursday">R
<input type="checkbox" name="friday" value="Friday">F
<input type="checkbox" name="saturday" value="Saturday" >Sa
<input type="checkbox" name="sunday" value="Tuesday">Su
</form>
</div>
</div>
</form>
</div>
CSS
.mid {background: #258db1; color: #fff; padding: 20px 0 30px 0;}
.mid h2 {color: #fff; text-align: center;}
.mid h2, .mid h3, .mid p, .footnote p {color:#fff;}
/* SEARCH */
#main-search-form {width: 100%;}
.search {min-width: 250px; display: inline; margin:0; position:relative;}
.search select {background: #fff; height: 40px; width: 150px; margin-bottom: 30px; margin-right: 30px; position:relative; display: inline;}
.search option, {padding: 10px; position:relative; display: inline;}
.search, .search label {display: inline;}
.search input#keywords {display: inline; position: relative; min-width: 250px; background: #fff; margin-right: 20px;}
.search .checkbox input {display: inline; position: relative; width: 15px!important; height: 15px!important; margin-left: 10px!important; margin-right: 2px!important;}
.search .checkbox label {display: inline; position: relative; margin-right: 10px;}
#media (max-width: 959px) {
.search {disply: block; clear:both;}
.search input, .search select, .search input#keywords {display:block; margin-bottom: 20px; margin-top: 8px; width: 60%!important; margin-left:30px;}
.search, .search label, .search input#keywords {display: block; clear:both;}
}
Remove align='center' attribute in #search