Forum Moderators: not2easy
I remember someone posting a neat example of how to layout a form as 2 columns like this:
Text ::form field::
Text ::form field::
- the forum fields should all line up nicely of course. I can't find the thread, anyone care to demonstrate?
I usually do mine like this:
Text:
::form field::
I quite like it but would like to try it the other way...
Thanks
Nick
This is how I do it. I'm not sure if the div.clear is needed or not.
The XHTML1 [w3.org] -
<div class="clear">
<div class="l">Your Name:</div>
<div class="r"><input type="text" name="name" /></div>
</div><br /><div class="clear">
<div class="l">Email Address:</div>
<div class="r"><input type="text" name="email" /></div>
</div><br />
The CSS [w3.org] -
div.l{float: left; width: 40%; text-align: right;}
div.r{float: right; width: 60%; text-align: left;}
.r input{width: 200px;}
div.clear{clear: both; height: 10px; font-size: 18px;}
<label for="fname">First Name:</label>
<input type="text" id="fname" name="firstname" maxlength="30">
GrahamS
<form action="post" style="width:450px">
<div class="row">
<label for="name">Name:</label>
<input id="name" class="formw" type="text" size="25">
</div>
<div class="row">
<label for="age">Age:</label>
<input id="age" class="formw" type="text" size="25">
</div>
<div class="row">
<label for="shoesize">Shoe size:</label>
<input id="shoesize" class="formw" type="text" size="25">
</div>
<div class="row">
<label for="comments">Comments:</label>
<textarea id="comments" class="formw" cols="25" rows="8">
Go ahead - write something...
</textarea>
</div>
<div style="clear:both;">
</div>
</form>
and then style the form directly with..
div.row {
clear: both;
padding-top: 10px;
}div.row label {
float: left;
width: 100px;
text-align: right;
}
div.row .formw {
float: right;
width: 335px;
text-align: left;
}
Maybe there was a good reason for those spans tho (browser inconsistencies?). Anyone know?
[CSS]
fieldset {
border:none;
display:table;
}
legend {
display:table-caption;
}
dl {
display:table-row;
}
dt, dd {
display:table-cell;
}
Making only appearance a table layout, after giving a suitable markup does not break specification. It can be said rather that it is right.
Strictly browsers such as Mozilla, display the above codes as an intention.