I have a large number of inputs I need to display. I am trying to condense them into like groups. The first group I am have is going to have 6 inputs in 3 columns but the third input box is big, so I want the next rows input to line up with the bottom of the larger text box. Form Layout
I have tried to float them, list them, use a table, but all without successs
I have looked at a lot of CSS code snippets and cannot figure out how to get this layout. Any help would be greatly appreciated.
Edit: I found a way to make it work, but would like a more elegant solution. HTML:
.row1 {
float: left;
background-color: #ffffff;
box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1);
font-family: Raleway, sans-serif;
text-align: center;
text-decoration: none;
padding: 5px;
}
.row2{
float: left;
background-color: #ffffff;
box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1);
font-family: Raleway, sans-serif;
text-align: center;
text-decoration: none;
padding: 5px;
}
.row3{
float: left;
display: inline-block;
clear: left;
position: relative;
margin-top: -80px;
}
<div class="row1">
<label>
<span>Full Project Number</span><br>
<input type="text" name="project" id="project">
</label>
</div>
<div class="row1">
<label>
<span>Client</span><br>
<input type="text" name="client" id="client">
</label>
</div>
</div>
<div class="row2 fasttimesatseedmonthigh">
<label id="descrp">
<span>Project Description</span><br>
<textarea name="name" type="text" cols="50" rows="10"></textarea>
</label>
</div>
<div class="row3">
<div class="row1">
<label for="drawing">
<span>Drawing Number</span><br>
<input type="text" name="drawing" id="drawing">
</label>
</div>
<div class="row1">
<label>
<span>Assigned By:</span><br>
<input type="text" name="assigned" id="assigned" style="width: 75px;">
</label>
</div>
<div class="row1">
<label class="form-row">
<span>Date</span><br>
<?php
$stamp=date("Y/m/d");?>
<input type="text" name="date" id="date" value="<?php echo(htmlspecialchars($stamp))?>"/>
</label>
</div>
</div>
It works but like I said not as nice as I would like it.
How about a good ol' table with row&colspan?
.grid{
border: solid 1px black;
table-layout: fixed;
font-family: Raleway, sans-serif;
border-spacing: 10px;
}
.grid td{
text-align: center;
vertical-align: top;
font-size: 9pt;
}
.grid td.wide{
width: 200px;
}
.grid td.normal{
width: 100px;
}
.grid td input{
width: 100%;
}
<table class="grid">
<tr>
<td colspan="2" class="wide">
<label>
<span>Full Project Number</span><br>
<input type="text" name="project" id="project">
</label>
</td>
<td colspan="2" class="wide">
<label>
<span>Client</span><br>
<input type="text" name="client" id="client">
</label>
</td>
<td colspan="2" rowspan="2">
<label id="descrp">
<span>Project Description</span><br>
<textarea name="name" type="text" cols="20" rows="8"></textarea>
</label>
</td>
</tr>
<tr>
<td colspan="1" class="normal">
<label for="drawing">
<span>Drawing Number</span><br>
<input type="text" name="drawing" id="drawing">
</label>
</td>
<td colspan="1" class="normal">
<label>
<span>Assigned By</span><br>
<input type="text" name="assigned" id="assigned">
</label>
</td>
<td colspan="2" class="wide">
<label class="form-row">
<span>Date</span><br>
<input type="text" name="date" id="date">
</label>
</td>
</tr>
</table>
Plis no hate.
Related
I am creating a credit card form in HTML and CSS. Everything is good so far, except the top portion where I display what is in the "Cart". I created a table so that the info can be evenly displayed. However, if you run the snippet, you can see that the table headers and data are not evenly spaced out. Can someone tell me what I am doing wrong? I tried using margin-left in the and class, but it does not work, it won't even shift to the left.
body {
font-family: Arial;
font-size: 17px;
padding: 8px;
}
* {
box-sizing: border-box;
}
.row {
display: -ms-flexbox; /* IE10 */
display: flex;
-ms-flex-wrap: wrap; /* IE10 */
flex-wrap: wrap;
margin: 0 -16px;
}
.col-25 {
-ms-flex: 25%; /* IE10 */
flex: 25%;
}
.col-50 {
-ms-flex: 50%; /* IE10 */
flex: 50%;
}
.col-75 {
-ms-flex: 75%; /* IE10 */
flex: 75%;
}
.col-25,
.col-50,
.col-75 {
padding: 0 16px;
}
.container {
background-color: #f2f2f2;
padding: 5px 20px 15px 20px;
border: 1px solid lightgrey;
border-radius: 3px;
}
input[type=text] {
width: 100%;
margin-bottom: 20px;
padding: 12px;
border: 1px solid #ccc;
border-radius: 3px;
}
label {
margin-bottom: 10px;
display: block;
}
.icon-container {
margin-bottom: 20px;
padding: 7px 0;
font-size: 24px;
}
.btn {
background-color: #4CAF50;
color: white;
padding: 12px;
margin: 10px 0;
border: none;
width: 100%;
border-radius: 3px;
cursor: pointer;
font-size: 17px;
}
.btn:hover {
background-color: #45a049;
}
a {
color: #2196F3;
}
hr {
border: 1px solid lightgrey;
}
span.price {
float: right;
color: grey;
}
<div class="row">
<div class="col-25">
<div class="container">
<h4>Cart</h4>
<table>
<tr>
<th>Company</th>
<th >Plan</th>
<th>Packages</th>
<th>Price/pckg</th>
<th>total</th>
</tr>
<tr>
<td>Joes Pizza</td>
<td>Premium</td>
<td>10,000</td>
<td>$0.039</td>
<td>390.00</td>
</tr>
</table>
<hr>
<p>Total <span class="price" style="color:black"><b>$390.00</b></span></p>
</div>
</div>
<div class="col-75">
<div class="container">
<form>
<div class="row">
<div class="col-50">
<h3>Billing Information</h3>
<label for="fname"><i class="fa fa-user"></i> Company Name</label>
<input type="text" id="fname" name="firstname">
<label for="email"><i class="fa fa-envelope"></i> Email</label>
<input type="text" id="email" name="email">
<label for="adr"><i class="fa fa-address-card-o"></i> Address</label>
<input type="text" id="adr" name="address">
<label for="city"><i class="fa fa-institution"></i> City</label>
<input type="text" id="city" name="city">
<div class="row">
<div class="col-50">
<label for="state">State</label>
<input type="text" id="state" name="state">
</div>
<div class="col-50">
<label for="zip">Zip</label>
<input type="text" id="zip" name="zip">
</div>
</div>
</div>
<div class="col-50">
<h3>Payment</h3>
<label for="fname">Accepted Cards</label>
<div class="icon-container">
<i class="fa fa-cc-visa" style="color:navy;"></i>
<i class="fa fa-cc-amex" style="color:blue;"></i>
<i class="fa fa-cc-mastercard" style="color:red;"></i>
<i class="fa fa-cc-discover" style="color:orange;"></i>
</div>
<label for="cname">Name on Card</label>
<input type="text" id="cname" name="cardname">
<label for="ccnum">Credit card number</label>
<input type="text" id="ccnum" name="cardnumber">
<label for="expmonth">Exp Month</label>
<input type="text" id="expmonth" name="expmonth">
<div class="row">
<div class="col-50">
<label for="expyear">Exp Year</label>
<input type="text" id="expyear" name="expyear">
</div>
<div class="col-50">
<label for="cvv">CVV</label>
<input type="text" id="cvv" name="cvv">
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-50">
<label for="ccnum">Bank Account</label>
<input type="text" id="ccnum" name="cardnumber">
</div>
<div class="col-50">
<label for="ccnum">Routing Number</label>
<input type="text" id="ccnum" name="cardnumber">
</div>
</div>
<input type="submit" value="Submit payment" class="btn">
</form>
</div>
</div>
</div>
The tables headers and the table data in your code are equally spaced but they do not look so because they are center-aligned. I have aligned td and th to left and gave padding for a better appearance and also gave the same widths to each th (no need to set widths in td if set in th).
Thanks
table tr th,
table tr td {
text-align: left;
padding: 2px 2px;
border: 1px solid black;
}
<div class="row">
<div class="col-25">
<div class="container">
<h4>Cart</h4>
<table>
<tr>
<th width="20%">Company</th>
<th width="20%">Plan</th>
<th width="20%">Packages</th>
<th width="20%">Price/pckg</th>
<th>total</th>
</tr>
<tr>
<td>Joes Pizza</td>
<td>Premium</td>
<td>10,000</td>
<td>$0.039</td>
<td>390.00</td>
</tr>
</table>
<hr>
<p>Total <span class="price" style="color:black"><b>$390.00</b></span></p>
</div>
</div>
How can I do that?
My HTML code is
<p> <input type="text" name="Usuari" size="20" maxlength="60"/>
<p>CLAU:</label> <input type="text" name="Clau" size="20" maxlength="20" /></p>
<p><input type="submit" name="submit" value="ACCÉS" /></p>-->
and my CSS code is
input {
padding: 5px;
font-weight: bold;
font-size: 1em;
color: #008040;
background: #FFFFFF;
border:1px dotted #004080;
}
I would place "USUARI:" and "CLAU:" into div with class and give them fixed size.
<div>
<div>
<div class="hints">
USUARI:
</div>
</div><input type="text" name="Usuari" size="20" maxlength="60"/>
</div>
<div>
<div class="hints">CLAU:
</div>
<input type="text" name="Clau" size="20" maxlength="20" />
</div>
</div>
<input type="submit" name="submit" value="ACCÉS" />
<style>
input {
padding: 5px;
font-weight: bold;
font-size: 1em;
color: #008040;
background: #FFFFFF;
border:1px dotted #004080;
}
.hints
{
width: 80px;
float: left;
}
</style>
https://jsfiddle.net/gm5wtw1e/
There are several ways to do that.
You can either use flex or with just a plain table:
<table>
<tr>
<td>Name:</td>
<td><input name="name"></td>
</tr>
<tr>
<td>Sur Name:</td>
<td><input name="surname"></td>
</tr>
</table>
---
<table>
<tr>
<td style="text-align: right;">Name:</td>
<td><input name="name"></td>
</tr>
<tr>
<td>Sur Name:</td>
<td><input name="surname"></td>
</tr>
</table>
p{
display: table-cell;
text-align: right;
}
input {
display: table-cell;
}
div.row{
display:table-row;
}
<div class="row"><p> <input type="text" name="Usuari" size="20" maxlength="60"/></div>
<div class="row"><p>CLAU:</label> <input type="text" name="Clau" size="20" maxlength="20" /></p></div>
<p><input type="submit" name="submit" value="ACCÉS" /></p>
label
{
display: block;
}
label span
{
display: inline-block;
text-align: left;
width: 100px;
}
<label>
<span>USARI:</span>
<input type="text" />
</label>
<label>
<span>CLAU:</span>
<input type="text" />
</label>
<label>
<span></span>
<input type="password" />
</label>
there are few error in your HTML code, you close the tag label but you never open it.
You should also wrap your fields in tag and wrap your label in tag .
You don't need to open the tag all the time, you can open it and close it at the beginning and at the end of the form.
There is also a --> at the end of the code, I assume that's another mistake.
Here is my solution to your question:
HTML
<label>
<span>USARI:</span>
<input type="text" />
</label>
<label>
<span>CLAU:</span>
<input type="text" />
</label>
<label>
<span></span>
<input type="password" />
</label>
And here is my css code:
CSS
label
{
display: block;
}
label span
{
display: inline-block;
text-align: left;
width: 100px;
}
You can now play with the CSS code in order to find the design that you like the most.
I am trying to achieve the below format design in HTML. I tried using multiple TR inside TD but i was not successful in getting the below design.
Please find the below code i have been trying:
#content {
position: absolute;
top: 110px;
left: 350px;
width: 775px;
height: 605px;
}
#content label {
display: block;
float: left;
margin-right: 4px;
vertical-align: top;
}
<div id="content">
<label>
Date Range
</label>
<label>
(Past)
<br />
<input id="myDatePast" type="text" style="width:31px;" />
</label>
<label>
(Future)
<br />
<input id="myDateFuture" type="text" style="width:31px;" />
</label>
<label>
<br />Total
<input id="myDateFuture" type="text" style="width:31px;" />Days
</label>
</div>
Well you can try something like this. I used table and css to style them.
table {
border: 1px solid #666;
border-collapse: collapse;
}
th,tr {width: 150px;}
th input {width: 50px;}
.th1-main {
border-right: 1px solid #666;
}
.th1-modify {margin-left: 60px;}
.th1-modify2 {margin-right: 60px;}
<div id="content">
<table>
<tr>
<th class="th1-main">
<span class="th1-modify">Date</span> <br>
<span class="th1-modify2">Range</span>
</th>
<th>
Past<br>
<input type="text" value="60"><br>
Date
</th>
<th>
Future<br>
<input type="text" value="360"><br>
Date
</th>
<th>
Total - <input type="text" value="420"> days
</th>
</tr>
</table>
</div>
Hope this was helpful.
table,#cell1{
border:2px solid gray;
border-collapse: collapse;
}
#total{
width:auto;height:50px;
}
#cell1{
width:100px;
height:75px;
}
td:not(.empty){
width:100px;
height:50px;
}
<div id="content">
<table>
<tr>
<td id="cell1">
<span style="float:right"><b>Date</b></span><br/><br/>
<span style="float:left"><b>Range</b></span> </td>
<td class="empty"></td>
<td>
(Past)
<br/>
<input id="myDatePast" type="text" value="60" style="width:31px;" /><br/><b>Date</b>
</td>
<td>
(Future)<br/>
<input id="myDateFuture" type="text" value="360" style="width:31px;" /><br/><b>Date</b>
</td>
<td id="total">
Total-
<input id="myDateFuture" type="text" value="420" style="width:31px;"/><b> Days</b>
</td>
</table>
</div>
A good setup would be
<table>
<tr>
<td>2</td><td>2</td>
</tr>
<tr>
<td>3</td><td>4</td>
</tr>
<tr>
<td>5</td><td>6</td>
</tr>
</table>
I just started coding a small page for myself after not doing any web design for a couple of years. As I now learned, laying out the page with tables is not state-of-the-art anymore (not sure if it ever really was).
Now I am trying to layout my page with CSS but couldn't find anything on:
How to align 7 checkboxes horizontally and put the corresponding label centered below the checkboxes?
How to align 2 selects horizontally and put the corresponding label centered above the selects?
The initial pure table-code was the following:
.form fieldset {
display: table;
border: 1px solid #c6c7cc;
border-radius: 5px;
}
.form label {
display: table-cell;
text-align: right;
padding: 5px;
}
.form input,
.form select {
display: table-cell;
}
.form .cssRow {
display: table-row;
}
.form .submit {
display: table-cell;
caption-side: bottom;
display: table-caption;
text-align: center;
}
<table>
<tr>
<td align="right">Name</td>
<td align="left">
<input name="name" type="text">
</td>
</tr>
<tr>
<td align="right">Day(s) of week</td>
<td align="center">
<table>
<tr>
<td align="center">
<input type="checkbox" name="day[]" value="mo" checked>
</td>
<td align="center">
<input type="checkbox" name="day[]" value="tu" checked>
</td>
<td align="center">
<input type="checkbox" name="day[]" value="we" checked>
</td>
<td align="center">
<input type="checkbox" name="day[]" value="th" checked>
</td>
<td align="center">
<input type="checkbox" name="day[]" value="fr" checked>
</td>
<td align="center">
<input type="checkbox" name="day[]" value="sa" checked>
</td>
<td align="center">
<input type="checkbox" name="day[]" value="su" checked>
</td>
</tr>
<tr>
<td align="center">Mo</td>
<td align="center">Tu</td>
<td align="center">We</td>
<td align="center">Th</td>
<td align="center">Fr</td>
<td align="center">Sa</td>
<td align="center">Su</td>
</tr>
</table>
</td>
</tr>
<tr>
<td align="right">Validity</td>
<td align="center">
<table>
<tr>
<td>Valid from</td>
<td>Valid to</td>
</tr>
<tr>
<td>
<select>
<option>January</option>
<option>February</option>
</select>
</td>
<td>
<select>
<option>January</option>
<option>February</option>
</select>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td align="center" colspan="2">
<input type="submit" name="submit" value="Refresh">
</td>
</tr>
</table>
My CSS attempt so far looks like this:
<div class="form">
<fieldset>
<legend>Search</legend>
<div class="cssRow">
<label for="name">Name</label>
<input name="name" type="text" size="30" maxlength="30">
</div>
<div class="cssRow">
<label for="day[]">Day(s) of week</label>
<input name="day[]" type="text" value="ToDo" size="30" disabled>
</div>
<div class="cssRow">
<label>Validity</label>
<input type="text" value="ToDo" size="30" disabled>
</div>
<div class="submit">
<input type="submit" name="submit" value="Suchen">
</div>
</fieldset>
</div>
To illustrate my problem, I created the following JSFiddle: http://jsfiddle.net/c9a7ezyk/
Any suggestions are welcome, although I prefer a simple solution, as I am just (re)learning HTML and CSS.
I prefer a slightly different approach to the other answer, where the <input> element is nested inside of a <label>, this implicitly associates the label with the input to give all kinds of nice bonuses.
It also makes for a simpler to follow markup, with less nested containers.
Example
<label>
<input type="checkbox">
<span class="label">Sunday</span>
</label>
And then
label {
display: inline-block;
text-align: center;
}
span.label {
display: block;
}
Notice how clicking the labels check the associated checkbox properly. Selects behave exactly the same way. Because <input> and <select> are inlines by default, it means that they'll be affected by text-align: center.
Checkbox with label:
<div class="checkbox-label">
<label for="checkbox">Sunday</label>
<div class="checkbox-container">
<input name="checkbox" type="checkbox">
</div>
</div>
.checkbox-label {
display: inline-block
}
.checkbox-container {
text-align: center;
}
Notice that the checkbox is inline so you can put it in a container and use text-align: center
Also notice that I use display: inline-block on .checkbox-label so that they can be aligned horizontally (block elements, default for div, takes up a whole line and drops the following element beneath it)
I use the same principals for the selects
You can see the whole thing here:
http://codepen.io/Vall3y/pen/QwdWOe
Semantic Purity
I am a bit of an HTML purist, so here is an HTML form without any extra markup:
The legends are floated to the left and vertically centered using a line-height that matches the legends height
The inputs are wrapped in a label with display: inline-block which is given a width to force the text below / above the input
The fieldset:before properties allow us to vertically center the labels with vertical-align: middle
Full Example
The background colours are just to illustrate the layout.
* {
margin: 0;
padding: 0;
}
fieldset {
border: none;
height: 70px;
}
fieldset:before {
content: '';
display: inline-block;
vertical-align: middle;
height: 100%;
background: #F90;
width: 0;
}
legend {
height: 100%;
line-height: 70px;
width: 150px;
text-align: center;
background: #F90;
float: left;
}
input[type=checkbox] {
margin: 0 5px;
}
.days label {
background: #F90;
width: 30px;
display: inline-block;
vertical-align: middle;
text-align: center;
}
.validity label {
background: #F90;
width: 100px;
display: inline-block;
vertical-align: middle;
text-align: center;
}
<form>
<fieldset class="days">
<legend>Day(s) of Week</legend>
<label for="monday">
<input type="checkbox" id="monday" />Mo
</label>
<label for="tuesday">
<input type="checkbox" id="tuesday" />Tu
</label>
<label for="wednesday">
<input type="checkbox" id="wednesday" />We
</label>
<label for="thursday">
<input type="checkbox" id="thursday" />Th
</label>
<label for="friday">
<input type="checkbox" id="friday" />Fr
</label>
<label for="saturday">
<input type="checkbox" id="saturday" />Sa
</label>
<label for="sunday">
<input type="checkbox" id="sunday" />Su
</label>
</fieldset>
<fieldset class="validity">
<legend>Validity</legend>
<label for="from">Valid From
<select id="from">
<option>Option</option>
</select>
</label>
<label for="to">Valid to
<select id="to">
<option>Option</option>
</select>
</label>
</fieldset>
</form>
Demo here
Here is the code:
<html>
<body>
<div>Name <input type="text"></input></div><br>
<div>Day(s) of week</div>
<div style="margin-left: 120px;margin-top: -25px;">
<div><input type="checkbox" checked><br>Mo</input></div>
<div style="
width: 10px;
margin-left: 30px;
margin-top: -37px;">
<input type="checkbox" checked><br>Tu</input></div>
<div style="
width: 10px;
margin-left: 60px;
margin-top: -37px;">
<input type="checkbox" checked><br>We</input></div>
<div style="
width: 10px;
margin-left: 90px;
margin-top: -37px;">
<input type="checkbox" checked><br>Th</input></div>
<div style="
width: 10px;
margin-left: 120px;
margin-top: -37px;">
<input type="checkbox" checked><br>Fr</input></div>
<div style="
width: 10px;
margin-left: 150px;
margin-top: -37px;">
<input type="checkbox" checked><br>Sa</input></div>
<div style="
width: 10px;
margin-left: 180px;
margin-top: -37px;"><input type="checkbox" checked><br>Su</input>
</div>
</div>
<br>
<div>Validity
<select>
<option>January</option>
<option>February</option>
</select>
<select>
<option>January</option>
<option>February</option>
</select>
</div>
</body>
</html>
I'm trying to right-align a dropdownlist similar to my textfields.
It works in firefox and IE, but I can't figure it out why it wont align properly in chrome.
HTML
<div id="metaDataEditInner">
<label>Document name</label>
<input class="field"></input>
<label>Document description</label>
<input class="field"></input>
<label>Document remarks</label>
<input class="field"></input>
<label>Document type</label>
<select class="dropdownfield">
</select>
<br />
<div style="clear:both">
<button id="test" class="defaultButton">Save metadata
</button>
</div>
</div>
CSS
#metaDataEditInner
{
margin: .5em 5px;
text-align: right;
width: 550px;
}
#metaDataEditInner label
{
float: left;
line-height: 1em;
margin-top: 3px;
}
#metaDataEditInner .field
{
border: 1px solid black;
width: 350px;
font-size: 12px;
line-height: 1em;
padding: 4px;
margin-bottom: 10px;
}
#metaDataEditInner .dropdownfield
{
border: 1px solid black;
width: 360px;
font-size: 12px;
line-height: 1em;
padding: 4px;
margin-bottom: 10px;
color:Black;
}
Any idea's ?
I've made a fiddle to illustrate the problem
http://jsfiddle.net/ZE5ss/2/
Thx!
I didn't want a say but if i saw you markup it's totally wrong.
1) Always put form element inside <form>.
2) input & button is an self closing element. Write like this:
<input class="field" />
<button id="test" class="defaultButton" value="Save metadata" />
3) select is not work without option Tag. Write like this:
<select class="dropdownfield">
<option></option>
</select>
Just remove the <br /> after the </select>. Works for me on chrome, see this fiddle.
Try this code its working fine in all the browsers:
<div id="metaDataEditInner">
<table>
<tr>
<td>
<label>Document name</label>
</td>
<td>
<input class="field"></input>
<tr>
<td>
<label>Document description</label>
</td>
<td>
<input class="field"></input>.
<tr>
<td>
<label>Document remarks</label>
</td>
<td>
<input class="field"></input>
<tr>
<td>
<label>Document type</label>
</td>
<td>
<select class="dropdownfield">
</select>
<tr>
<td> </td>
<td>
<button id="test" class="defaultButton">Save metadata
</button>
</tr>
</table>
</div>