I am making a little form and have some line-breaks so that the text boxes are ontop of eachother. I can't seem to get the submit button and radio buttons to the right to start at the top of the form. Any ideas on what I need to do to achieve my goal design?I just need to shift the stuff to the right of the input text boxes up so they are inline with the "Restaurant Name" box
main {
margin-left: 88px;
margin-right: 88px;
}
#search_button {
height: 35px;
width: 60px;
border: 1px solid #ebebeb;
background-color: #bb0000;
font-size: 1em;
color: white;
border-radius: 8px;
margin-left: 12px;
cursor: pointer;
}
.textbox {
padding-left: 8px;
margin-bottom: 5px;
height: 28px;
width: 400px;
border: 1px solid #ebebeb;
border-radius: 3px;
}
<main>
<img id="header" src="images/header.jpeg">
<div>
<form>
<input type="text" placeholder="Restaurant Name" class="textbox"><br/>
<input type="text" placeholder="Location" class="textbox">
<button type="submit" id="search_button">
<i class="fa fa-search"></i>
</button>
<input type="radio" value="Best Match" name="search_terms">
<label>Best Match</label>
<input type="radio" value="Review Count" name="search_terms">
<label>Review Count</label> <br/>
<input type="radio" value="Rating" name="search_terms">
<label>Rating</label>
<input type="radio" value="Distance" name="search_terms">
<label>Distance</label> <br/>
</form>
</div>
</main>
My Current Code (BAD):
My Design Goal:
flexbox would be the best here. It has all the needed stuff to format your design to specifications. Also, don't be afraid to use divs, they exist to be used to format. HTML needs to be foolproof, since it will be used on a large number of devices, and it is prone to breaking if you do not nest well enough.
main {
margin-left: 88px;
margin-right: 88px;
}
#search_button {
height: 35px;
width: 60px;
border: 1px solid #ebebeb;
background-color: #bb0000;
font-size: 1em;
color: white;
border-radius: 8px;
margin-left: 12px;
cursor: pointer;
}
.textbox {
padding-left: 8px;
margin-bottom: 5px;
height: 28px;
width: 100%;
max-width: 400px;
box-sizing: border-box;
border: 1px solid #ebebeb;
border-radius: 3px;
}
.form {
display: flex;
flex-direction: row;
align-items: flex-start;
}
.left, .right {width: 50%;}
<main>
<img id="header" src="images/header.jpeg">
<div>
<form class="form">
<div class="left">
<input type="text" placeholder="Restaurant Name" class="textbox"><br/>
<input type="text" placeholder="Location" class="textbox">
</div>
<div class="right">
<button type="submit" id="search_button">
<i class="fa fa-search"></i>
</button>
<input type="radio" value="Best Match" name="search_terms">
<label>Best Match</label>
<input type="radio" value="Review Count" name="search_terms">
<label>Review Count</label> <br/>
<input type="radio" value="Rating" name="search_terms">
<label>Rating</label>
<input type="radio" value="Distance" name="search_terms">
<label>Distance</label> <br/>
</div>
</form>
</div>
</main>
I had to add a few more divs in order to make it cleanly.
When in doubt, use flexbox.
Biggest change is spliting your form into columns using flexbox and then using again flexbox in those columns to create desired layout.
Lines that I have added has been marked with /* added */. html you will figure out yourself.
main {
margin-left: 88px;
margin-right: 88px;
}
form { /* added */
display: flex; /* added */
column-gap: 12px; /* added */
} /* added */
.form-column { /* added */
width: fit-content; /* added */
display: flex; /* added */
flex-wrap: wrap; /* added */
} /* added */
.textbox {
padding-left: 8px;
margin-bottom: 5px;
height: 28px;
max-width: 400px;
width: 100%; /* added */
border: 1px solid #ebebeb;
border-radius: 3px;
}
.radio-group { /* added */
flex: 0 0 50%; /* added */
max-width: 50%; /* added */
} /* added */
#search_button {
height: 35px;
width: 60px;
border: 1px solid #ebebeb;
background-color: #bb0000;
font-size: 1em;
color: white;
border-radius: 8px;
cursor: pointer;
}
<main>
<form>
<div class="form-column">
<input type="text" placeholder="Restaurant Name" class="textbox">
<input type="text" placeholder="Location" class="textbox">
</div>
<div class="form-column">
<button type="submit" id="search_button">
<i class="fa fa-search"></i>
</button>
</div>
<div class="form-column">
<div class="radio-group">
<input type="radio" value="Best Match" name="search_terms">
<label>Best Match</label>
</div>
<div class="radio-group">
<input type="radio" value="Review Count" name="search_terms">
<label>Review Count</label>
</div>
<div class="radio-group">
<input type="radio" value="Rating" name="search_terms">
<label>Rating</label>
</div>
<div class="radio-group">
<input type="radio" value="Distance" name="search_terms">
<label>Distance</label>
</div>
</div>
</form>
</main>
This can be done well with flexbox. In addition to #GhostPengy, I have added a flexbox to the right area.
main {
margin-left: 88px;
margin-right: 88px;
}
#search_button {
height: 35px;
width: 60px;
border: 1px solid #ebebeb;
background-color: #bb0000;
font-size: 1em;
color: white;
border-radius: 8px;
margin-left: 12px;
cursor: pointer;
}
.textbox {
padding-left: 8px;
margin-bottom: 5px;
height: 28px;
width: 100%;
max-width: 400px;
box-sizing: border-box;
border: 1px solid #ebebeb;
border-radius: 3px;
}
.form {
display: flex;
flex-direction: row;
align-items: flex-start;
}
.left, .right {width: 50%;}
.right {
display: flex;
}
<main>
<img id="header" src="images/header.jpeg">
<div>
<form class="form">
<div class="left">
<input type="text" placeholder="Restaurant Name" class="textbox"><br/>
<input type="text" placeholder="Location" class="textbox">
</div>
<div class="right">
<div>
<button type="submit" id="search_button">
<i class="fa fa-search"></i>hello
</button>
</div>
<div>
<input type="radio" value="Best Match" name="search_terms">
<label>Best Match</label>
<input type="radio" value="Review Count" name="search_terms">
<label>Review Count</label> <br/>
<input type="radio" value="Rating" name="search_terms">
<label>Rating</label>
<input type="radio" value="Distance" name="search_terms">
<label>Distance</label> <br/>
</div>
</div>
</form>
</div>
</main>
Use display flex for making it desired and responsive for all kind of screens.
Code below - Working example here.
HTML -
<main>
<div>
<form>
<div class="form-container">
<div class="col-50">
<input
type="text"
placeholder="Restaurant Name"
class="textbox"
/><br />
<input type="text" placeholder="Location" class="textbox" />
</div>
<div class="col-50">
<div>
<button type="submit" id="search_button">
<i class="fa fa-search"></i>
</button>
</div>
<div class="radio-buttons-container">
<label class="radio-element">
<input type="radio" value="Best Match" name="search_terms" />
Best Match</label
>
<label class="radio-element">
<input type="radio" value="Review Count" name="search_terms" />
Review Count</label
>
<label class="radio-element">
<input type="radio" value="Rating" name="search_terms" />
Rating</label
>
<label class="radio-element">
<input type="radio" value="Distance" name="search_terms" />
Distance</label
>
<br />
</div>
</div>
</div>
</form>
</div>
</main>
And CSS -
* {
box-sizing: border-box;
}
main {
padding: 24px;
}
main .form-container {
display: flex;
gap: 8px;
flex-wrap: wrap;
}
.form-container .col-50 {
flex: 1;
min-width: 200px;
}
.form-container .col-50:last-of-type {
display: flex;
gap: 8px;
}
.radio-buttons-container {
display: flex;
flex-wrap: wrap;
}
.radio-buttons-container .radio-element {
min-width: 50%;
white-space: nowrap;
}
#search_button {
height: 35px;
width: 60px;
border: 1px solid #ebebeb;
background-color: #bb0000;
font-size: 1em;
color: white;
border-radius: 8px;
cursor: pointer;
}
.textbox {
padding-left: 8px;
margin-bottom: 5px;
height: 28px;
width: 100%;
max-width: 100%;
border: 1px solid #ebebeb;
border-radius: 3px;
}
You can divide form in two columns like this and can further customize CSS properties on those
You can open the following code snippet in full screen or can checkout the same on Codepen, you can make it responsive accordingly too
main {
margin-left: 88px;
margin-right: 88px;
}
#search_button {
height: 35px;
width: 60px;
border: 1px solid #ebebeb;
background-color: #bb0000;
font-size: 1em;
color: white;
border-radius: 8px;
margin-left: 12px;
cursor: pointer;
}
.textbox {
padding-left: 8px;
margin-bottom: 5px;
height: 28px;
width: 400px;
border: 1px solid #ebebeb;
border-radius: 3px;
}
* {
box-sizing: border-box;
}
.column {
float: left;
padding: 10px;
}
.row:after {
content: "";
display: table;
clear: both;
}
<main>
<img id="header" src="images/header.jpeg">
<div>
<form>
<div class="row">
<div class="column">
<input type="text" placeholder="Restaurant Name" class="textbox"><br />
<input type="text" placeholder="Location" class="textbox">
<button type="submit" id="search_button">
<i class="fa fa-search"></i>
</button>
</div>
<div class="column">
<input type="radio" value="Best Match" name="search_terms">
<label>Best Match</label>
<input type="radio" value="Review Count" name="search_terms">
<label>Review Count</label> <br />
<input type="radio" value="Rating" name="search_terms">
<label>Rating</label>
<input type="radio" value="Distance" name="search_terms">
<label>Distance</label> <br />
</div>
</div>
</form>
</div>
</main>
Related
I am aiming to make text boxes that adapt to the size of the browser window. I'm using css flex properties. The textboxes in the code below do not adapt with the screen size, and I'm not sure exactly why. I believe it might be because I have an outer div that's interacting with the css properties for the actual textboxes.
One other thing that I'm not sure how to do, is to align the button to the right edge of the text boxes, so that the button does not go past the textboxes. Because the textboxes are not dynamically reshaping their width I'm not sure how to proceed with the button.
.search_btn {
width: 150px;
padding: 10px;
background-color: black;
color: white;
border: 0;
}
.search_btn:hover {
box-shadow: 1px 1px 1px grey;
/*background-color: darkblue;*/
}
input {
justify-content: flex-left;
padding: 5px;
position: absolute;
margin-left: 200px;
}
.txt_box {
display: flex;
width: 80%;
}
.search_section {
/*padding: 5px;*/
padding-top: 10px;
padding-bottom: 10px;
}
.search_options {
padding-bottom: 10px;
}
.row {
display: flex;
flex-direction: row;
align-items: left;
justify-content: left;
padding-top: 10px;
padding-bottom: 10px;
}
<form action="/action_page.php">
<div class="search_section">
<div class="search_options">
<h3 class="tit_label" for="fname">SHAPES</h3>
<div class="row">
<label class="left_label" for="fname">average square:</label>
<!-- <div id="wrapper" -->
<input class="txt_box" type="text" id="fname" name="fname" />
</div>
<div class="row">
<label class="left_label" for="lname">average circle:</label>
<input class="txt_box" type="text" id="lname" name="lname" />
</div>
</div>
<div class="form-buttons">
<input class="search_btn" type="submit" value="calculate" />
</div>
</div>
</form>
You need to remove position: absolute from input to make it flex-item. Since you have made absolute positioned then it comes out of the normal flow, then you don't need to use display: flex on input.
No need to use the below style, since txt_box will be a flex item then it will adjust its width accordingly
.txt_box { // Not Required
display: flex;
width: 80%;
}
There is no such property justify-content: flex-left;. There is justify-content: flex-start; instead
.search_btn {
width: 150px;
padding: 10px;
background-color: black;
color: white;
border: 0;
}
.search_btn:hover {
box-shadow: 1px 1px 1px grey;
}
input {
padding: 5px;
}
.search_section {
padding-top: 10px;
padding-bottom: 10px;
}
.search_options {
padding-bottom: 10px;
}
.row {
display: flex;
padding-top: 10px;
padding-bottom: 10px;
}
.left_label {
flex-basis: 20%;
}
.txt_box {
margin: 0;
flex-basis: 80%;
}
<form action="/action_page.php">
<div class="search_section">
<div class="search_options">
<h3 class="tit_label" for="fname">SHAPES</h3>
<div class="row">
<label class="left_label" for="fname">average square:</label>
<input class="txt_box" type="text" id="fname" name="fname" />
</div>
<div class="row">
<label class="left_label" for="lname">average circle:</label>
<input class="txt_box" type="text" id="lname" name="lname" />
</div>
</div>
<div class="form-buttons">
<input class="search_btn" type="submit" value="calculate" />
</div>
</div>
</form>
I have this page, I'm using fleboxes and I need to the boxes be something like
My code now:
<div class="cardActions">
<h2 style="display:inline">Card Actions | <i class="fas fa-home"></i> </h2> >> eCommerce >> Eletronics
</div>
<div class="filters">
<div class="container column">
<p style="margin-top: 8%; margin-bottom: 5%; margin-left: 4% ;font-weight: bold;"> Multi Range
</p>
<div class="checkBoxes">
<input type="radio" name="multiRange" style="display: inline;" id="radio1">
<label for="radio1">$10</label> <br>
<input type="radio" name="multiRange" id="radio2">
<label for="radio2">$10-$100</label> <br>
<input type="radio" name="multiRange" id="radio3">
<label for="radio3">$100-$500</label> <br>
<input type="radio" name="multiRange" id="radio4">
<label for="radio4">$500</label> <br>
<input type="radio" name="multiRange" id="radio5">
<label for="radio5">All</label>
</div>
<p style="font-weight: bold; margin-top: 10%; margin-left: 4%">
Slider<input type="text" id="amount" readonly style="border:0; font-weight:bold; background-color: #ffab00; margin-left: 35%;">
</p>
<div style="background-color: #091e42; width: 80%; margin-left: 5%; margin-right: 5%; margin-top: 10%; margin-bottom: 10%;"
id="slider-range"></div>
<hr class="solid">
<p style="margin-top: 10%; margin-left: 4% ; margin-bottom: 10%; font-weight: bold;"> Category
</p>
<div class="checkBoxes">
<input type="checkbox" id="check1"> <label for="check1">Teste</label> <br>
<input type="checkbox" id="check2"> <label for="check2">Teste</label> <br>
<input type="checkbox" id="check3"> <label for="check3">Teste</label> <br>
<input type="checkbox" id="check4"> <label for="check4">Teste</label> <br>
<input type="checkbox" id="check5"> <label for="check5">Teste</label> <br>
<input type="checkbox" id="check6"> <label for="check6">Teste</label> <br>
<input type="checkbox" id="check7"> <label for="check7">Teste</label> <br>
<input type="checkbox" id="check8"> <label for="check8">Teste</label> <br>
<input type="checkbox" id="check9"> <label for="check9">Teste</label> <br>
<input type="checkbox" id="check10"> <label for="check10">Teste</label>
</div>
<hr class="solid">
<p style="margin-top: 10%; margin-bottom: 10%; margin-left: 4%; font-weight: bold;">
Brand
</p>
<div class="checkBoxes">
<input type="checkbox" id="check1"> <label for="check1">Teste</label> <br>
<input type="checkbox" id="check2"> <label for="check2">Teste</label> <br>
<input type="checkbox" id="check3"> <label for="check3">Teste</label> <br>
<input type="checkbox" id="check4"> <label for="check4">Teste</label> <br>
<input type="checkbox" id="check5"> <label for="check5">Teste</label> <br>
<input type="checkbox" id="check6"> <label for="check6">Teste</label> <br>
<input type="checkbox" id="check7"> <label for="check7">Teste</label> <br>
<input type="checkbox" id="check8"> <label for="check8">Teste</label> <br>
<input type="checkbox" id="check9"> <label for="check9">Teste</label> <br>
<input type="checkbox" id="check10"> <label for="check10">Teste</label>
</div>
<hr class="solid">
<p style="margin-top: 10%; margin-bottom: 10%; margin-left: 4%; font-weight: bold;">
Rating
</p>
<div class="rating">
<span style="color: white;">☆</span>
<span>☆</span>
<span>☆</span>
<span>☆</span>
<span>☆</span>
</div>
<div class="rating">
<span style="color: white;">☆</span>
<span>☆</span>
<span>☆</span>
<span>☆</span>
<span>☆</span>
</div>
<div class="rating">
<span style="color: white;">☆</span>
<span>☆</span>
<span>☆</span>
<span>☆</span>
<span>☆</span>
</div>
</div> <!--Fim-->
The css:
#import url('https://fonts.googleapis.com/css?family=Josefin+Sans&display=swap');
*{
margin: 0;
padding: 0;
box-sizing: border-box;
list-style: none;
text-decoration: none;
font-family: 'Josefin Sans', sans-serif;
}
body{
background-color: #f3f5f9;
}
.wrapper{
display: flex;
position: relative;
}
.wrapper .sidebar{
width: 200px;
height: 100%;
background: #091e42;
padding: 30px 0px;
position: fixed;
}
.wrapper .sidebar h2{
color: #fff;
text-transform: uppercase;
text-align: center;
margin-bottom: 30px;
}
.wrapper .sidebar ul li{
padding: 15px;
border-bottom: 1px solid #bdb8d7;
border-bottom: 1px solid rgba(0,0,0,0.05);
border-top: 1px solid rgba(255,255,255,0.05);
}
.wrapper .sidebar ul li a{
color: #bdb8d7;
display: block;
}
.wrapper .sidebar ul li a .fas{
width: 25px;
}
.wrapper .sidebar ul li:hover{
background-color: #36b37e;
}
.wrapper .sidebar ul li:hover a{
color: #fff;
}
.wrapper .sidebar .social_media{
position: absolute;
bottom: 0;
left: 50%;
transform: translateX(-50%);
display: flex;
}
.wrapper .sidebar .social_media a{
display: block;
width: 40px;
background: #36b37e;
height: 40px;
line-height: 45px;
text-align: center;
margin: 0 5px;
color: #bdb8d7;
border-top-left-radius: 5px;
border-top-right-radius: 5px;
}
.wrapper .main_content{
width: 100%;
margin-left: 200px;
}
.wrapper .main_content .header{
padding: 20px;
background: #fff;
color: #717171;
border-bottom: 1px solid #e0e4e8;
}
.header{
padding: 20px;
background: #fff;
color: #717171;
border-bottom: 1px solid #e0e4e8;
margin-top: 1%;
margin-bottom: 1%;
margin-left: 2%;
margin-right: 2%;
}
.filters{
width: 18%;
height: 88%;
background-color: #ffab00;
display: flex;
flex-wrap: wrap;
margin-left: 1%;
margin-top: 1%;
border-radius: 10px;
}
.cardActions{
margin-left: 2%;
}
.wrapper .main_content .info{
margin: 20px;
color: #717171;
line-height: 25px;
}
.wrapper .main_content .info div{
margin-bottom: 20px;
}
#media (max-height: 500px){
.social_media{
display: none !important;
}
}
.topIcons{
margin-right: 2%;
}
.container {
margin: 0 auto;
display: flex;
}
.column {
flex-direction: column;
height: fit-content;
width: 100%;
justify-content: flex-start;
}
input[type="radio"]{
margin-left: 4%;
margin-bottom: 5%;
}
input[type="checkbox"]{
margin-left: 4%;
margin-bottom: 5%;
}
hr.solid {
border-top: 1px solid white;
margin-left: 4%;
margin-right: 4%;
}
/* Products */
.products{
width: 78%;
height: 13%;
background-color: #091e42;
flex-direction: row;
display: block;
margin-left: 50%;
}
/* Rating */
/*
Ratings Stars
(with as little code as possible)
*/
.rating {
unicode-bidi: bidi-override;
direction: rtl;
text-align: center;
color: white;
font-size: x-large;
}
.rating > span {
display: inline-block;
position: relative;
width: 1.1em;
}
.rating > span:hover,
.rating > span:hover ~ span {
color: transparent;
}
.rating > span:hover:before,
.rating > span:hover ~ span:before {
content: "\2605";
position: absolute;
left: 0;
color: gold;
}
Right now I cant manage to make this, can someone help me?
I need to create boxes like the red ones in the picture.
I tried everything and still can't make this work.
Is there something i'm missing or making wrong?
All you need to do is, put a sibling to your filter div and make their parent display: flex; one did this, then give the remaining width to your right side red-bordered section. for example, you have give filter width: 18%; margin-left: 1%; which makes it 19% and now you have 81% in hand, so distribute it accordingly in width and margin to right side div. Apply other stylings as per you need.
#import url('https://fonts.googleapis.com/css?family=Josefin+Sans&display=swap');
*{
margin: 0;
padding: 0;
box-sizing: border-box;
list-style: none;
text-decoration: none;
font-family: 'Josefin Sans', sans-serif;
}
body{
background-color: #f3f5f9;
}
.wrapper{
display: flex;
position: relative;
}
.wrapper .sidebar{
width: 200px;
height: 100%;
background: #091e42;
padding: 30px 0px;
position: fixed;
}
.wrapper .sidebar h2{
color: #fff;
text-transform: uppercase;
text-align: center;
margin-bottom: 30px;
}
.wrapper .sidebar ul li{
padding: 15px;
border-bottom: 1px solid #bdb8d7;
border-bottom: 1px solid rgba(0,0,0,0.05);
border-top: 1px solid rgba(255,255,255,0.05);
}
.wrapper .sidebar ul li a{
color: #bdb8d7;
display: block;
}
.wrapper .sidebar ul li a .fas{
width: 25px;
}
.wrapper .sidebar ul li:hover{
background-color: #36b37e;
}
.wrapper .sidebar ul li:hover a{
color: #fff;
}
.wrapper .sidebar .social_media{
position: absolute;
bottom: 0;
left: 50%;
transform: translateX(-50%);
display: flex;
}
.wrapper .sidebar .social_media a{
display: block;
width: 40px;
background: #36b37e;
height: 40px;
line-height: 45px;
text-align: center;
margin: 0 5px;
color: #bdb8d7;
border-top-left-radius: 5px;
border-top-right-radius: 5px;
}
.wrapper .main_content{
width: 100%;
margin-left: 200px;
}
.wrapper .main_content .header{
padding: 20px;
background: #fff;
color: #717171;
border-bottom: 1px solid #e0e4e8;
}
.header{
padding: 20px;
background: #fff;
color: #717171;
border-bottom: 1px solid #e0e4e8;
margin-top: 1%;
margin-bottom: 1%;
margin-left: 2%;
margin-right: 2%;
}
.filters{
width: 18%;
height: 88%;
background-color: #ffab00;
display: flex;
flex-wrap: wrap;
margin-left: 1%;
margin-top: 1%;
border-radius: 10px;
}
.cardActions{
margin-left: 2%;
}
.wrapper .main_content .info{
margin: 20px;
color: #717171;
line-height: 25px;
}
.wrapper .main_content .info div{
margin-bottom: 20px;
}
#media (max-height: 500px){
.social_media{
display: none !important;
}
}
.topIcons{
margin-right: 2%;
}
.container {
margin: 0 auto;
display: flex;
}
.column {
flex-direction: column;
height: fit-content;
width: 100%;
justify-content: flex-start;
}
input[type="radio"]{
margin-left: 4%;
margin-bottom: 5%;
}
input[type="checkbox"]{
margin-left: 4%;
margin-bottom: 5%;
}
hr.solid {
border-top: 1px solid white;
margin-left: 4%;
margin-right: 4%;
}
/* Products */
.atul {
display: flex;
}
.rightSide {
display: flex;
flex-direction: column;
padding: 10px;
border: 1px solid red;
border-radius: 4px;
width: 80%;
margin-left: 1%;
}
.subSection{
min-height: 50px;
height: 100%;
margin-bottom: 20px;
padding: 10px;
border: 1px solid red;
border-radius: 4px;
}
.products{
width: 78%;
height: 13%;
background-color: #091e42;
flex-direction: row;
display: block;
margin-left: 50%;
}
/* Rating */
/*
Ratings Stars
(with as little code as possible)
*/
.rating {
unicode-bidi: bidi-override;
direction: rtl;
text-align: center;
color: white;
font-size: x-large;
}
.rating > span {
display: inline-block;
position: relative;
width: 1.1em;
}
.rating > span:hover,
.rating > span:hover ~ span {
color: transparent;
}
.rating > span:hover:before,
.rating > span:hover ~ span:before {
content: "\2605";
position: absolute;
left: 0;
color: gold;
}
<div class="cardActions">
<h2 style="display:inline">Card Actions | <i class="fas fa-home"></i> </h2> >> eCommerce >> Eletronics
</div>
<section class="atul">
<div class="filters">
<div class="container column">
<p style="margin-top: 8%; margin-bottom: 5%; margin-left: 4% ;font-weight: bold;"> Multi Range
</p>
<div class="checkBoxes">
<input type="radio" name="multiRange" style="display: inline;" id="radio1">
<label for="radio1">$10</label> <br>
<input type="radio" name="multiRange" id="radio2">
<label for="radio2">$10-$100</label> <br>
<input type="radio" name="multiRange" id="radio3">
<label for="radio3">$100-$500</label> <br>
<input type="radio" name="multiRange" id="radio4">
<label for="radio4">$500</label> <br>
<input type="radio" name="multiRange" id="radio5">
<label for="radio5">All</label>
</div>
<p style="font-weight: bold; margin-top: 10%; margin-left: 4%">
Slider<input type="text" id="amount" readonly style="border:0; font-weight:bold; background-color: #ffab00; margin-left: 35%;">
</p>
<div style="background-color: #091e42; width: 80%; margin-left: 5%; margin-right: 5%; margin-top: 10%; margin-bottom: 10%;" id="slider-range"></div>
<hr class="solid">
<p style="margin-top: 10%; margin-left: 4% ; margin-bottom: 10%; font-weight: bold;"> Category
</p>
<div class="checkBoxes">
<input type="checkbox" id="check1"> <label for="check1">Teste</label> <br>
<input type="checkbox" id="check2"> <label for="check2">Teste</label> <br>
<input type="checkbox" id="check3"> <label for="check3">Teste</label> <br>
<input type="checkbox" id="check4"> <label for="check4">Teste</label> <br>
<input type="checkbox" id="check5"> <label for="check5">Teste</label> <br>
<input type="checkbox" id="check6"> <label for="check6">Teste</label> <br>
<input type="checkbox" id="check7"> <label for="check7">Teste</label> <br>
<input type="checkbox" id="check8"> <label for="check8">Teste</label> <br>
<input type="checkbox" id="check9"> <label for="check9">Teste</label> <br>
<input type="checkbox" id="check10"> <label for="check10">Teste</label>
</div>
<hr class="solid">
<p style="margin-top: 10%; margin-bottom: 10%; margin-left: 4%; font-weight: bold;">
Brand
</p>
<div class="checkBoxes">
<input type="checkbox" id="check1"> <label for="check1">Teste</label> <br>
<input type="checkbox" id="check2"> <label for="check2">Teste</label> <br>
<input type="checkbox" id="check3"> <label for="check3">Teste</label> <br>
<input type="checkbox" id="check4"> <label for="check4">Teste</label> <br>
<input type="checkbox" id="check5"> <label for="check5">Teste</label> <br>
<input type="checkbox" id="check6"> <label for="check6">Teste</label> <br>
<input type="checkbox" id="check7"> <label for="check7">Teste</label> <br>
<input type="checkbox" id="check8"> <label for="check8">Teste</label> <br>
<input type="checkbox" id="check9"> <label for="check9">Teste</label> <br>
<input type="checkbox" id="check10"> <label for="check10">Teste</label>
</div>
<hr class="solid">
<p style="margin-top: 10%; margin-bottom: 10%; margin-left: 4%; font-weight: bold;">
Rating
</p>
<div class="rating">
<span style="color: white;">☆</span>
<span>☆</span>
<span>☆</span>
<span>☆</span>
<span>☆</span>
</div>
<div class="rating">
<span style="color: white;">☆</span>
<span>☆</span>
<span>☆</span>
<span>☆</span>
<span>☆</span>
</div>
<div class="rating">
<span style="color: white;">☆</span>
<span>☆</span>
<span>☆</span>
<span>☆</span>
<span>☆</span>
</div>
</div>
</div>
<div class="rightSide">
<div class="subSection"></div>
<div class="subSection"></div>
<div class="subSection"></div>
<div class="subSection"></div>
</div>
</section>
<div id='listpage'> //here it should be flex-direction:column
<div class='list'>
<div></div>
<div></div>
<div></div>
</div>
<div class='list'>
<div></div>
<div></div>
<div></div>
</div>
</div>
I want to create this form in css
HTML
<div class="contact__right">
<form action="" class="contact__form">
<div>
<label for="name" class="contact__form-label">Name</label>
<input type="text" id="name" class="contact__form-input">
</div>
<div>
<label for="email" class="contact__form-label">Email</label>
<input type="text" id="email" class="contact__form-input">
</div>
<div>
<label for="phone" class="contact__form-label">Phone</label>
<input type="text" id="phone" class="contact__form-input">
</div>
<div>
<label for="message" class="contact__form-label">Message</label>
<textarea name="message" id="message" cols="30" rows="10" class="contact__form-textarea"></textarea>
</div>
</form>
</div>
CSS
.contact {
&__form {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
padding: 105px 95px;
color: $white;
}
&__form-input,
&__form-textarea {
width: 300px;
height: 40px;
background: transparent;
border: 1px solid white;
border-radius: 2px;
margin-bottom: 25px;
}
&__form-textarea {
height: 150px;
}
&__form-label {
padding-right: 70px;
}
}
What I'm struggling with is alignment of inputs with labels and of textarea at the same line vertically.
textarea always sticks out at the side, because of its label which has longer text than the rest.
All the help will be appreciated.
I would not use a flexbox for the form, but for each <div> inside the form. The labels are vertically centered for each input field, except for the textarea. There the label is vertically aligned at the top. You can play with top padding there when desired.
* {
box-sizing: border-box;
}
.contact__right {
background-color: gray;
}
.contact__form {
padding: 105px 95px;
width: 100%;
color: white;
}
.contact__form>div {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 25px;
}
.contact__form-input,
.contact__form-textarea {
width: 300px;
height: 40px;
background: transparent;
border: 1px solid white;
border-radius: 2px;
}
.contact__form-textarea {
height: 150px;
}
label[for="message"].contact__form-label {
align-self: flex-start;
}
<div class="contact__right">
<form action="" class="contact__form">
<div>
<label for="name" class="contact__form-label">Name</label>
<input type="text" id="name" class="contact__form-input">
</div>
<div>
<label for="email" class="contact__form-label">Email</label>
<input type="text" id="email" class="contact__form-input">
</div>
<div>
<label for="phone" class="contact__form-label">Phone</label>
<input type="text" id="phone" class="contact__form-input">
</div>
<div>
<label for="message" class="contact__form-label">Message</label>
<textarea name="message" id="message" cols="30" rows="10" class="contact__form-textarea"></textarea>
</div>
</form>
</div>
Add following css code and your problem will be solved.
.contact__form-label {
vertical-align: top;}
Add this CSS rule for label:
label {
width: 100px;
display: inline-block;
vertical-align: top;
}
(otherwise label will be treated as an inline-element. This way you give it a fixed width and align it to the top)
If you don't like the alignment at the very top, you can add a padding-top ike in the following snippet:
form {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
padding: 105px 95px;
color: $white;
}
input,
textarea {
width: 300px;
height: 40px;
background: transparent;
border: 1px solid white;
border-radius: 2px;
margin-bottom: 25px;
}
textarea {
height: 150px;
}
label {
width: 100px;
display: inline-block;
vertical-align: top;
padding-top: 14px;
}
.contact__right {
background: #ccc;
}
<div class="contact__right">
<form action="" class="contact__form">
<div>
<label for="name" class="contact__form-label">Name</label>
<input type="text" id="name" class="contact__form-input">
</div>
<div>
<label for="email" class="contact__form-label">Email</label>
<input type="text" id="email" class="contact__form-input">
</div>
<div>
<label for="phone" class="contact__form-label">Phone</label>
<input type="text" id="phone" class="contact__form-input">
</div>
<div>
<label for="message" class="contact__form-label">Message</label>
<textarea name="message" id="message" cols="30" rows="10" class="contact__form-textarea"></textarea>
</div>
</form>
</div>
´
You are gonna have to do that manually I guess. Normally websites tend to break line after the labels and bring the input fields to the next line.
I want to design the responsive contact form where the layout is name, email, subject fields be in one column and message field be in the another column. I could not make that message field appear in another column though I have used the width as 50%. Here is the demo
http://jsbin.com/vuxojuqeve/edit?html,css,output
The code
#responsive-form {
max-width: 600px;
margin: 0 auto;
width: 100%;
}
.form-row {
width: 100%;
}
.form-row input {
margin: 10px 0;
}
.clearfix:after {
content: "";
display: table;
clear: both;
}
.button {
float: left;
background: #CA0002;
color: #fff;
text-transform: uppercase;
border: none;
padding: 8px 20px;
cursor: pointer;
}
input[type="text"],
textarea {
width: 100%;
padding: 8px;
border: 1px solid #ccc;
border-radius: 3px;
box-sizing: border-box
}
.half-size {
width: 50%;
}
<div id="responsive-form" class="clearfix">
<div class="half-size">
<div class="form-row">
<div class="column">
<input type="text" name="name" class="form-control">
</div>
</div>
<div class="form-row">
<div class="column">
<input type="text" name="name" class="form-control">
</div>
</div>
<div class="form-row">
<div class="column">
<input type="text" name="name" class="form-control">
</div>
</div>
<div class="form-row">
<div class="column">
<input type="text" name="name" class="form-control">
</div>
</div>
</div>
<div class="half-size">
<div class="form-row">
<div class="column">
<textarea class="form-control" cols="40" rows="10"></textarea>
</div>
</div>
</div>
<div class="form-row">
<div class="column">
<input type="submit" name="name" class="button">
</div>
</div>
</div>
</div>
This is what I wanted with submit button on the left column
You need to set your containers to display:inline-block, as they are block level elements by default and won't allow others to be positioned beside them.
I'm using 45% because 50% + 50% is not usually 100% when using inline-blocks because of an issue with whitespace, there are some ways around it, I'll let you decide for yourself which hack to use...
#responsive-form {
max-width: 600px;
margin: 0 auto;
width: 100%;
}
.form-row {
width: 100%;
}
.form-row input {
margin: 10px 0;
}
.clearfix:after {
content: "";
display: table;
clear: both;
}
.button {
float: left;
background: #CA0002;
color: #fff;
text-transform: uppercase;
border: none;
padding: 8px 20px;
cursor: pointer;
}
input[type="text"],
textarea {
width: 100%;
padding: 8px;
border: 1px solid #ccc;
border-radius: 3px;
box-sizing: border-box
}
.half-size {
width: 45%;
display:inline-block;
}
<div id="responsive-form" class="clearfix">
<div class="half-size">
<div class="form-row">
<div class="column">
<input type="text" name="name" class="form-control">
</div>
</div>
<div class="form-row">
<div class="column">
<input type="text" name="name" class="form-control">
</div>
</div>
<div class="form-row">
<div class="column">
<input type="text" name="name" class="form-control">
</div>
</div>
<div class="form-row">
<div class="column">
<input type="text" name="name" class="form-control">
</div>
</div>
</div>
<div class="half-size">
<div class="form-row">
<div class="column">
<textarea class="form-control" cols="40" rows="10"></textarea>
</div>
</div>
</div>
<div class="form-row">
<div class="column">
<input type="submit" name="name" class="button">
</div>
</div>
</div>
</div>
If there are columns, use flexbox.
Inputs and textarea width unit is vw and e.g. min-width: 180px.
Example
body {
margin: 0;
}
::placeholder,
input[type="submit"] {
color: #BACEE7;
font-weight: bold;
}
.form {
display: flex;
justify-content: center;
padding: 15px;
}
.form input,
.form textarea {
min-width: 180px;
background: #F2F2F2;
border: 1px solid #ccc;
text-transform: uppercase;
border-radius: 3px;
text-align: center;
box-sizing: border-box;
}
.form>.inputs {
margin-right: 5px;
}
.form>.inputs>input {
width: 30vw;
display: block;
margin-bottom: 5px;
padding: 1.5vw;
}
.form>.inputs>input:last-child {
margin-bottom: 0 !important;
}
.form textarea {
width: 35vw;
padding-top: 80px;
display: block;
height: 100%;
}
.form input[type="submit"] {
background: #CA0002;
color: white;
border: none;
cursor: pointer;
}
<div class="form">
<div class="inputs">
<input type="text" name="first_name" placeholder="first name">
<input type="text" name="last_name" placeholder="last name">
<input type="email" name="email" placeholder="email">
<input type="text" name="organization" placeholder="organization">
<input type="tel" name="phone" placeholder="phone">
<input type="submit" name="submit">
</div>
<div class="textarea">
<textarea name="" id="" cols="30" placeholder="message"></textarea>
</div>
</div>
I am having an issue where I am using text-align on my container to center all of the content within it, but would like to align my <span> elements to the left within that centered container. I have tried isolating the span elements in my css and using text-align: left; but have not had any success. I feel like it is a simple fix that is slipping my mind at the moment, but hope that it can be easily resolved.
HTML:
<div class="grid">
<div class="col-1-1" id="bar-registration-container">
<h1>Register</h1>
<div id="form-fields">
<form>
<label class="form-label" id="email">
<span>Email</span>
<br />
<input id="email" type="email" name="email" />
</label>
<br />
<label class="form-label" id="password">
<span>Password</span>
<br />
<input id="password" type="password" name="password" />
</label>
<br />
<label>
<input class="form-label" id="submit" type="submit" value="Register" />
</label>
</form>
</div>
</div>
</div>
CSS:
#bar-registration-container h1{
text-align: center;
}
#form-fields {
text-align: center;
background-color: #fff;
margin: 0 auto;
padding: 20px;
}
#form-fields input[type=email] {
font-size: 27px;
margin-bottom: 20px;
}
#form-fields input[type=password] {
font-size: 27px;
margin-bottom: 10px;
}
.form-label span {
color: #000;
margin-right: 10px;
}
#submit {
margin-top: 20px;
width: 300px;
height: 30px;
background-color: #000;
color: #fff;
font-size: 15px;
border: none;
}
I believe this snippet accomplishes what you want. I just gave the form-fields div a set width, and added a few styles to those span elements to get them to stretch the full width of that div, but be left-aligned.
#bar-registration-container h1{
text-align: center;
}
#form-fields {
width: 340px;
text-align: center;
background-color: #fff;
margin: 0 auto;
padding: 20px;
}
#form-fields input[type=email] {
font-size: 27px;
margin-bottom: 20px;
}
#form-fields input[type=password] {
font-size: 27px;
margin-bottom: 10px;
}
.form-label span {
display: inline-block;
text-align: left;
color: #000;
width: 100%;
margin-left: 5px;
}
#submit {
margin-top: 20px;
width: 300px;
height: 30px;
background-color: #000;
color: #fff;
font-size: 15px;
border: none;
}
<div class="grid">
<div class="col-1-1" id="bar-registration-container">
<h1>Register</h1>
<div id="form-fields">
<form>
<label class="form-label" id="email">
<span>Email</span>
<br />
<input id="email" type="email" name="email" />
</label>
<br />
<label class="form-label" id="password">
<span>Password</span>
<br />
<input id="password" type="password" name="password" />
</label>
<br />
<label>
<input class="form-label" id="submit" type="submit" value="Register" />
</label>
</form>
</div>
</div>
</div>
In order to left align your <span> you need to left align them and in edition to that you will have to use display:block. You actually were on right track you just missed display:block. Using display:block will make your <span> to act as a block element like <div> or <p> and then it will respect alignment properties better.
span{
text-align:left;
display:block;
margin-left:50px;// adjust yourself. Was just playing around with it.
}