I am having troubles with centering and aligning the forms inside the divs
I can't get the green to size properly and centre the form inside the green.
BTW the pic is what it looks like on my computer, when you click the code snippet, it looks all jumbled.
<style type="text/css">
#div1 {
background-color: coral;
width: 33.33%;
float: right;
height: 200px;
text-align: center;
}
#div1_Child {
width: 100%;
height: 60%;
border: 0px solid blue;
margin: 0 auto;
text-align: center;
}
#div2 {
background-color: rgb(240, 191, 191);
width: 33.33%;
float: left;
height: 200px;
text-align: center;
}
#div2_Child {
width: 90%;
height: 60%;
border: 0px solid blue;
margin: 0 auto;
text-align: left;
}
#div3 {
background-color: aqua;
width: 33.33%;
margin: 0 auto;
height: 200px;
text-align: center;
}
#div3_Child {
width: 85%;
height: 60%;
border: 0px solid blue;
margin: 0 auto;
text-align: center;
padding: 5px;
}
label {
width: 200px;
display: inline-block;
text-align: right;
}
form {
border-radius: 10px;
background: green;
color: black;
width: 80%;
padding: 2px;
margin: 0 auto;
}
</style>
<div id="div1">Div1 Right
<h1>Lighter Load</h1>
<div id="div1_Child">
<form>
<label for="beams">Beam Thickness</label>
<select name="Beams" id="beam">
<option value="Select">Select</option>
<option value="3.5">3.5</option>
<option value="5.25">5.25</option>
<option value="7">7</option>
</select><br>
<label for="dead">Dead</label>
<input id="dead2" type="text" name="dead" onkeyup="ecCalc()"><br>
<label>Eccentric</label>
<input id="eccCalc" type="text" name="total"><br>
<label>Index</label>
<input type="text" id="ecc">
</form>
</div>
</div>
<div id="div2">Div2 Left
<h1>Post Height</h1>
<div id="div2_Child">
<form class="form">
<label for="column_Height">Column Height:</label>
<select id="column_Height" onchange="search1()";>
<option value="">Select</option>
<option value="90">89</option>
<option value="96">90</option>
<option value="102">96</option>
<option value="120">102</option>
<option value="144">120</option>
<option value="168">144</option>
<option value="192">168</option>
<option value="216">192</option>
<option value="216">216</option>
</select> <br>
<label for="value">Between</label>
<input type="text" id="value" size="4" disabled>
<label for="text">and</label>
<input type="text" id="text" size="4" disabled><br>
<label for="l_oad" class= "label1">Unfactored</label>
<input type="text" id="l_oad" onkeyup="search()" placeholder="Unfactored.." title="Load" size="15">
</form>
</div>
</div>
<div id="div3">Div3 Middle
<h1>Heaver Loads</h1>
<div id="div3_Child">
<form>
<label>Dead</label>
<input id="dead1" type="text" name="dead" onkeyup="total_1()" size="10px"><br>
<label>Live</label>
<input class="input1" id="live1" type="text" name="live" onkeyup="total_1()" size="10"><br>
<label>Total</label>
<input id="total1" type="text" name="total" size="10"><br>
</form>
</div>
</div>
Why won't you use flex box? For more info about flex box look here: link. For all row divs you can still use flexbox example flex-direction: row;. Width of items inside will corresponds to your screen width.
* { box-sizing: border-box; margin: auto; padding: auto; }
.container_main { width: auto; height: 400px; background: red; padding: 10px; display: flex; flex-direction: row; overflow: auto; }
.container_main .item { width: 100%; height: 100%; background: yellow; margin: 0 5px; padding: 5px }
.container_main form { height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.container_main form .form_item { width: 100%; height: 32px; display: flex; flex-direction: row; align-items: center; justify-content: center; }
<div class="container_main">
<div class="item">
<form method="post">
<div class="form_item">
<span>something</span>
<input type="text"/>
</div>
<div class="form_item">
<span>something</span>
<input type="text"/>
</div>
<div class="form_item">
<span>something</span>
<input type="text"/>
</div>
</form>
</div>
<div class="item">
<form method="post">
<div class="form_item">
<span>something</span>
<input type="text"/>
</div>
<div class="form_item">
<span>something</span>
<input type="text"/>
</div>
<div class="form_item">
<span>something</span>
<input type="text"/>
</div>
</form>
</div>
<div class="item">
<form method="post">
<div class="form_item">
<span>something</span>
<input type="text"/>
</div>
<div class="form_item">
<span>something</span>
<input type="text"/>
</div>
<div class="form_item">
<span>something</span>
<input type="text"/>
</div>
</form>
</div>
</div>
Related
I intend to have a long input form centered. AFTER THAT I need to place a submit button 15px after the form's right end. Could you please help me to code it? Thank you.
Note: I want to have only the form centered and after that add a button.
My attempt:
<div style="background-color: red; width: 100%; ">
<form action="file.php">
<center><input type="text" name="c2" style="width: 79%; font-size:25pt;"></center>
<input type="submit" value="send" style="position: relative; left: 15px">
</form>
</div>
Adding a photo:
Flexbox would be one of several possibilities.
.wrapper {
display:flex;
align-items: center;
justify-content: center;
}
.inp {
width: 79%;
font-size:25pt;
}
<div style="background-color: red; width: 100%; ">
<form action="file.php">
<div class="wrapper">
<input type="text" name="c2" class="inp">
<br/>
<input type="submit" value="send" style="position: relative; left: 15px">
</div>
</form>
</div>
UPDATED (again)
.main { display: flex; }
.a, .b, .c { background: red; }
.b { flex: 1; text-align: center; }
.c {margin-left: auto;}
.inp {
width: 79%;
font-size:25pt;
}
.sub {
position: relative;
right: 15px;
top:10px;
}
<div class="main">
<div class="a"></div>
<div class="b">
<form action="file.php">
<div class="wrapper">
<input type="text" name="c2" class="inp">
</div>
</form>
</div>
<div class="c">
<input type="submit" value="send" class="sub">
</div>
</div>
UPDATE (2)
.wrapper {
display:flex;
align-items: center;
justify-content: center;
}
.inp {
width: 79%;
font-size:25pt;
position: relative; left: 15px
}
.sub {
position: relative; left: 30px
}
<div style="background-color: red; width: 100%; ">
<form action="file.php">
<div class="wrapper">
<input type="text" name="c2" class="inp">
<br/>
<input type="submit" value="send" class="sub">
</div>
</form>
</div>
You can do something like this, using flexbox.
https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout/Flexbox
.form-container {
background-color: red;
width: 100%;
display:flex;
flex-flow: row nowrap;
justify-content:center;
padding: 10px 0;
}
<form action="file.php">
<div class="form-container">
<input type="text" name="c2" style="width: 79%; font-size:25pt;">
<input type="submit" value="send" style="position: relative; left: 15px">
</div>
</form>
I need to center a survey form in my website, but when I try it, it doesn't work. I don't know what's wrong. Can somebody help me?
Here is my Pen. And here's my CSS code:
*,
*::before,
*::after {
box-sizing: border-box;
}
body {
font-family: 'Poppins', sans-serif;
font-size: 1rem;
font-weight: 400;
line-height: 1.4;
color: var(--color-white);
margin: 0;
}
/* mobile friendly alternative to using background-attachment: fixed */
body::before {
content: '';
position: fixed;
top: 0;
left: 0;
height: 100%;
width: 100%;
z-index: -1;
background: var(--color-darkblue);
background-image: linear-gradient(
115deg,
rgba(58, 58, 158, 0.8),
rgba(136, 136, 206, 0.7)
),
url(https://cdn.freecodecamp.org/testable-projects-fcc/images/survey-form-background.jpeg);
background-size: cover;
background-repeat: no-repeat;
background-position: center;
}
.container {
width: 100%;
margin: 3.125rem auto 0 auto;
}
you can use this on your body
body {
background-color: lightblue;
font-family: Helvetica;
font-size: 16px;
flex: 0 1 auto;
align-self: auto;
width: 100%;
text-align: center;
}
It is not recommended to use body directly and style it. But I made a few tweaks on your code to keep letting you use body directly.
Please check this out for reference when you want to center an element.
https://css-tricks.com/centering-css-complete-guide/
*,
*::before,
*::after {
box-sizing: border-box;
}
.wrapper {
margin: 0 auto; // this centers bloc elements
text-align: center; // This centers inline elements
}
header {
width: 100%;
}
body {
width: 100%; // just let your body take 100% of the page
background-color: lightblue;
font-family: Helvetica;
font-size: 16px;
position: absolute;
flex: 0 1 auto;
align-self: auto;
}
#survey-form {
border: solid 2px;
border-radius: 1%;
padding: 20px;
margin-top: 30px;
background-color: lightpink;
position: relative;
}
.form input {
width: 100%;
height: 30px;
}
.container {
display: flex;
justify-content: flex-start;
flex-direction: column;
//border: solid 2px #fff;
max-width: 700px;
margin: auto;
}
h1 {
color: darkblue;
}
p {
font-weight: bold;
}
form {
text-align: left;
}
#dropdown {
width: 100%;
height: 30px;
}
.checkbox {
display: flex;
flex-direction: column;
}
#submit {
height: 20px;
width: 100%;
background-color: #bbh77f;
color: #000;
padding: 0 20px;
text-align: center;
vertical-align: middle;
}
.input-textarea {
min-height: 120px;
width: 100%;
margin-bottom: 15px;
resize: vertical;
}
<!DOCTYPE html>
<html>
<head>
<meta>
<title>Formularz</title>
</head>
<body>
<header>
<div class='wrapper'>
<h1 id="title">Formularz freeCodeCamp.org</h1>
<p id="description">Dziękujemy za poświęcony czas i ulepszanie naszej platformy</p>
</div>
</header>
<div class="container">
<form id="survey-form">
<div class="form box">
<div>
<label id="name-label" for="name"><p>Imię</p></label>
<input id="name" type="text" required placeholder="Wpisz swoje imię" />
</div>
<div>
<label id="email-label" for="mail"><p>E-mail</p></label>
<input id="name" type="email" required placeholder="Wpisz swój e-mail" />
</div>
<div>
<label id="number-label" for="number"><p>Wiek</p></label>
<input type="number" min="10" max="99" placeholder="10">
</div>
</div>
<div class="form-group">
<p id="dropdown-label">Która opcja najlepiej Cię opisuje?</p>
<select id="dropdown">
<option disabled selected value>Wybierz swoją rolę</option>
<option value="student">Student</option>
<option value="full-time-job">Pełen etat</option>
<option value="full-time-learner">Uczeń</option>
<option value="prefer-not-to-say">Nie chcę mówić</option>
<option value="other">Inne</option>
</select>
</div>
<div class="form-radio">
<p id="radio-label">Czy poleciłbyś freeCodeCamp znajomemu?</p>
<div>
<input type="radio" id="tak" name="polecenie" value="tak" checked>
<label for="tak">Tak</label>
</div>
<div>
<input type="radio" id="nie" name="polecenie" value="nie">
<label for="nie">Nie</label>
</div>
<div>
<input type="radio" id="nie-wiem" name="polecenie" value="nie-wiem">
<label for="nie-wiem">Nie wiem</label>
</div>
</div>
<div class="form-group">
<p id="dropdown-label">Jaka część freeCodeCamp jest Twoją ulubioną?</p>
<select id="dropdown">
<option disabled selected value>Wybierz opcję</option>
<option value="challenges">Challenges</option>
<option value="projects">Projects</option>
<option value="community">Community</option>
<option value="open-source">Open source</option>
</select>
</div>
<div class="form-group checkbox">
<p>Co chcesz ulepszyć?</p>
<div>
<input type="checkbox">
<label>Front-end Projects</label>
</div>
<div>
<input type="checkbox">
<label>Back-end Projects</label>
</div>
<div>
<input type="checkbox" checked>
<label>Data Visualization</label>
</div>
<div>
<input type="checkbox">
<label>Challenges</label>
</div>
<div>
<input type="checkbox">
<label>Open Source Community</label>
</div>
<div>
<input type="checkbox">
<label>Gitter help rooms</label>
</div>
<div>
<input type="checkbox">
<label>Videos</label></div>
<div>
<input type="checkbox">
<label>City Meetups</label></div>
<div>
<input type="checkbox">
<label>Wiki</label>
</div>
<div>
<input type="checkbox">
<label>Forum</label>
</div>
<div>
<input type="checkbox">
<label>Additional Courses</label>
</div>
</div>
<div class="form-group">
<p>Masz sugestie lub podpowiedzi? </p>
<div class="textarea container input-textarea">
<textarea rows="8" placeholder="Wprowadź swoją opinię tutaj"></textarea>
</div>
<button id="submit">Wyślij</button>
</div>
</div>
</form>
</div>
</div>
</body>
</html>
I have a problem. CSS isn't my favorite part of coding and I can't figure this out. I need the following result:
But here is what I have now:
#newOrderControl {
border-style: solid;
border-color: black;
border-width: 1px;
width: min-content;
font-size: 14px;
}
#newOrderInputFields {
display: grid;
grid-template-columns: auto auto auto auto;
column-gap: 40px;
}
#newOrderInputFields .inputField {
display: flex;
align-items: center;
flex-direction: row;
}
#newOrderInputFields label {
width: auto;
}
#newOrderButtons button {
float: right;
border-style: solid;
border-color: black;
border-width: 2px;
color: white;
height: 30px;
width: auto;
padding: 0px 15px;
text-align: center;
text-decoration: none;
font-size: 16px;
border-radius: 10px;
margin: 0px 5px;
}
.btnAll {
background-color: #6DA0ED;
border-style: solid;
border-color: black;
border-width: 1px;
color: white;
border-radius: 5px;
}
#btnTakeProfit {
background-color: #33AB37;
}
#btnPlaceOrder {
background-color: #6DA0ED;
}
.title {
display: block;
text-align: center;
color: #1D0F73;
font-size: 22px;
font-weight: bold;
margin: 5px;
}
<div id="newOrderControl">
<label class="title">New order</label>
<div id="newOrderInputFields">
<div class="inputField">
<label>Action:</label>
<select id="txtOrderAction">
<option value="">-</option>
<option value="Buy">Buy</option>
<option value="Sell">Sell</option>
</select>
</div>
<div class="inputField">
<label>Quantity:</label>
<div>
<input type="text" id="txtOrderQuantity">
<button class="btnAll" onclick="setAllQuantity()">All</button>
</div>
</div>
<div class="inputField">
<label>Target price:</label>
<input type="text" id="txtOrderTargetPrice">
</div>
<div class="inputField">
<label>Target perc:</label>
<input type="text" id="txtOrderTargetPerc">
</div>
<div class="inputField">
<label>Coin:</label>
<select id="txtOrderCoin">
<option value="">-</option>
</select>
</div>
<div class="inputField">
<label>Amount:</label>
<div>
<input type="text" id="txtOrderAmount">
<button class="btnAll" onclick="setAllAmount()">All</button>
</div>
</div>
<div class="inputField">
<label>Limit price:</label>
<input type="text" id="txtOrderLimitPrice">
</div>
<div class="inputField">
<label>Limit perc:</label>
<input type="text" id="txtOrderLimitPerc">
</div>
</div>
<div id="newOrderButtons">
<button id="btnTakeProfit">Take profit</button>
<button id="btnPlaceOrder">Place order</button>
</div>
</div>
With this code I currently have the following problems:
My All button isn't next to the input field
The 2 buttons below are outside the newOrderControl div
The labels are being wrapped to the next line
All inputs and labels need to be aligned below each other like a grid
Now I have tried to change it to a grid, but then I was struggling with the input and button that are next to each other. So I wrapped them in a div, but then they completely disappear.
What do I need to do to get the result?
(1) Removing the wrapper <div> in below code will automatically align the input and buttons by the power of flexbox.
<div>
<input type="text" id="txtOrderQuantity">
<button class="btnAll" onclick="setAllQuantity()">All</button>
</div>
(2) First rule: do not use float for layout.
I've added:
#newOrderControl {
display: flex;
flex-direction: column;
So that buttons can be aligned to the right with
#newOrderInputFields label {
width: auto;
}
(3) Applying flex-shrink: 0; will prevent the <label> from wrapping. I've changed the width of container to width: max-content; and reduced gap to compensate for it.
(4) added justify-content: flex-end; to align them:
#newOrderInputFields .inputField {
display: flex;
flex-direction: row;
justify-content: flex-end;
#newOrderControl {
display: flex;
align-items: center;
flex-direction: column;
border-style: solid;
border-color: black;
border-width: 1px;
width: max-content;
font-size: 14px;
}
#newOrderInputFields {
display: grid;
grid-template-columns: auto auto auto auto;
column-gap: 5px;
}
#newOrderInputFields .inputField {
display: flex;
flex-direction: row;
justify-content: flex-end;
align-items: center;
}
#newOrderInputFields label {
width: auto;
flex-shrink: 0;
}
#newOrderButtons {
align-self: flex-end;
}
#newOrderButtons button {
float: right;
border-style: solid;
border-color: black;
border-width: 2px;
color: white;
height: 30px;
width: auto;
padding: 0px 15px;
text-align: center;
text-decoration: none;
font-size: 16px;
border-radius: 10px;
margin: 0px 5px;
}
.btnAll {
background-color: #6DA0ED;
border-style: solid;
border-color: black;
border-width: 1px;
color: white;
border-radius: 5px;
}
#btnTakeProfit {
background-color: #33AB37;
}
#btnPlaceOrder {
background-color: #6DA0ED;
}
.title {
display: block;
text-align: center;
color: #1D0F73;
font-size: 22px;
font-weight: bold;
margin: 5px;
}
<div id="newOrderControl">
<label class="title">New order</label>
<div id="newOrderInputFields">
<div class="inputField">
<label>Action:</label>
<select id="txtOrderAction">
<option value="">-</option>
<option value="Buy">Buy</option>
<option value="Sell">Sell</option>
</select>
</div>
<div class="inputField">
<label>Quantity:</label>
<input type="text" id="txtOrderQuantity">
<button class="btnAll" onclick="setAllQuantity()">All</button>
</div>
<div class="inputField">
<label>Target price:</label>
<input type="text" id="txtOrderTargetPrice">
</div>
<div class="inputField">
<label>Target perc:</label>
<input type="text" id="txtOrderTargetPerc">
</div>
<div class="inputField">
<label>Coin:</label>
<select id="txtOrderCoin">
<option value="">-</option>
</select>
</div>
<div class="inputField">
<label>Amount:</label>
<input type="text" id="txtOrderAmount">
<button class="btnAll" onclick="setAllAmount()">All</button>
</div>
<div class="inputField">
<label>Limit price:</label>
<input type="text" id="txtOrderLimitPrice">
</div>
<div class="inputField">
<label>Limit perc:</label>
<input type="text" id="txtOrderLimitPerc">
</div>
</div>
<div id="newOrderButtons">
<button id="btnTakeProfit">Take profit</button>
<button id="btnPlaceOrder">Place order</button>
</div>
</div>
Hey, so I'm trying to build a movie review site which uses a database (I'm using PouchDB) and I want to style my admin/add a review page so that the inputs and labels are all aligned in a certain way. I keep adjusting widths, padding and margins but I just cant seem to get them to align. Can someone teach me how to align them the way i want them to be please?
This is how I want them to look:
body {
margin: 0;
font-family: georgia, arial;
background-color: #e0e0e0;
text-align: center;
}
.newFilm {
text-align: left;
display: inline-block;
background-color: green;
width: 80%;
padding: 20px;
}
label {
padding: 6px;
text-align: center;
background: red;
}
.form {
display: flex;
text-align: center;
flex-direction: column;
}
input {
margin: 10px;
width: 40%;
background-color: yellow;
padding: 8px;
border: 2px;
}
<div class="newFilm">
<h2 id='formTitle'>Create new review</h2>
<div class="form">
<form>
<label for="title">Title:</label><input type="text" id="title">
<label for="genre">Genre:</label><input type="text" id="genre">
<label for="image">Image:</label><input type="text" id="image">
<label for="rating">Rating:</label><input type="number" id="rating">
<label for="synopsis">Synopsis:</label><input type="text" id="synopsis">
<label for="trailer">Trailer:</label><input type="text" id="trailer">
<input type="hidden" id="id">
<button id="modifyFilmButton">Post review!</button>
</form>
</div>
</div>
you can use either flex or grid or both. I've used both just as an example. you could also use only grid and nest a grid within a grid.
body {
margin: 0;
font-family: georgia, arial;
background-color: #e0e0e0;
text-align: center;
}
.newFilm {
background-color: green;
max-width: 100%;
padding: 10%;
display: grid;
grid-template-columns: 1fr 1fr;
grid-gap: 30px;
}
#formTitle {
grid-column: 1/3;
}
#modifyFilmButton {
grid-column: 2/3;
width: 50%;
justify-self: end;
}
.left {
display: flex;
justify-content: center;
flex-direction: column;
text-align: left;
}
.right {
display: flex;
flex-direction: column;
text-align: left;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>temp</title>
<link rel="stylesheet" type="text/css" href="temp.css" />
</head>
<body>
<div class="newFilm">
<h2 id="formTitle">Create new review</h2>
<div class="left">
<label for="title">Title:</label><input type="text" id="title" />
<label for="image">Image:</label><input type="text" id="image" />
<label for="trailer">Trailer:</label><input type="text" id="trailer" /> <input type="hidden" id="id" />
<label for="rating">Rating:</label><input type="number" id="rating" />
</div>
<div class="right">
<label for="genre">Genre:</label><input type="text" id="genre" />
<label for="synopsis">Synopsis:</label><input type="text" id="synopsis" />
</div>
<button id="modifyFilmButton">Post review!</button>
</div>
<script src="temp.js"></script>
</body>
</html>
Modified your html a little to add some structure.
I would not recommend using this code, look into bootstrap tables, or something of that nature. It will look better, and be a more scaleable solution.
.newFilm {
background-color: red;
padding: 20px;
border-radius: 20px;
}
textarea,
input,
label {
display: block
}
textarea,
input {
width: 200px;
}
.form {
width: 100%;
}
.left,
.right {
width: 49%;
display: inline-block;
vertical-align: top;
}
<div class="newFilm">
<h2 id='formTitle'>Create new review</h2>
<div class="form">
<form>
<div class="left">
<label for="title">Title:</label>
<input type="text" id="title">
<label for="genre">Genre:</label>
<input type="text" id="genre">
<label for="image">Image:</label>
<input type="text" id="image">
<label for="rating">Rating:</label>
<input type="number" id="rating">
</div>
<div class="right">
<label for="synopsis">Synopsis:</label>
<input type="text" id="synopsis">
<label for="trailer">Trailer:</label>
<textarea id="trailer" rows="5"></textarea>
<input type="hidden" id="id">
<button id="modifyFilmButton">Post review!</button>
</div>
</form>
</div>
</div>
Responsive solution:
.myForm {
background-color: red;
padding: 20px;
border-radius: 20px;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" rel="stylesheet" />
<div class="container-fluid myForm">
<div class="row">
<div class="col-lg"><h1>Create New Review</h1></div>
</div>
<form>
<div class="row">
<div class="col-md"> <!-- left column -->
<div class="form-group">
<label>Title</label>
<input type="text" class="form-control">
</div>
<div class="form-group">
<label>Genre</label>
<input type="text" class="form-control">
</div>
<div class="form-group">
<label>Image</label>
<input type="text" class="form-control">
</div>
<div class="form-group">
<label>Rating</label>
<input type="text" class="form-control">
</div>
</div>
<div class="col-md"> <!-- right column -->
<div class="form-group">
<label>Synopsis</label>
<input type="text" class="form-control">
</div>
<div class="form-group">
<label>Trailer</label>
<textarea class="form-control"></textarea>
</div>
<input class="btn btn-primary" type="submit" value="Submit" disabled>
</div>
</div>
</form>
</div>
Adjust the left/right columns to have your desired effect.
See: https://getbootstrap.com/docs/4.1/layout/grid/
Well there are couple ways to do that.
My best option would be to have one big div that would hold two smaller divs.
Then give those two divs width of 50% each - i have used grid for that.
After that you want to make sure that label and input are taking full width of their container.
Like that you will achieve most of what you want. Also for Synopsis you should use textarea not input.
Here is my example on codepen.
Here is what I did
body {
margin: 0;
font-family: georgia, arial;
background-color: #e0e0e0;
text-align: center;
}
.newFilm {
text-align: left;
display: inline-block;
background-color: green;
width: 80%;
padding: 20px;
}
label {
padding: 6px;
color: #fff;
display: block;
text-align: left;
}
.form {
display: flex;
text-align: center;
flex-direction: column;
}
.row {
display: grid;
grid-template-columns: 1fr 1fr;
}
.col {
padding: 20px;
}
input,
textarea {
width: 100%;
display: block;
background-color: yellow;
padding: 8px;
border: 2px;
}
#modifyFilmButton {
float: right;
}
<div class="newFilm">
<h2 id='formTitle'>Create new review</h2>
<div class="form">
<form>
<div class="row">
<div class="col">
<label for="title">Title:</label><input type="text" id="title">
<label for="image">Image:</label><input type="text" id="image">
<label for="trailer">Trailer:</label><input type="text" id="trailer">
<label for="rating">Rating:</label><input type="number" id="rating">
</div>
<div class="col">
<label for="genre">Genre:</label><input type="text" id="genre">
<label for="synopsis">Synopsis:</label>
<textarea rows="9" id="synopsis"></textarea>
</div>
</div>
<input type="hidden" id="id">
<button id="modifyFilmButton">Post review!</button>
</form>
</div>
</div>
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>