Forum Moderators: not2easy
Here's an example, using tables.
<form ...>
<table>
<tr>
<td>
Name
</td>
<td>
<input blah>
</td>
<td>
Type your name here.
</td>
</tr>
<tr>
<td>
Birthdate
</td>
<td>
<input blah>
</td>
<td>
Enter your birthdate here.
</td>
</tr>
</table>
</form>
What is the correct way to do this, not using tables? I tried using 3 separate divs (left, middle, right).
<div style="float:left; width: 30%;">
Name:
</div>
<div style="float:left; width: 30%;">
<input ...>
</div>
<div style="float:left; width: 30%;">
Enter your name.
</div>
<br style = "clear:both">
<div style="float:left; width: 30%;">
Birthdate
</div>
<div style="float:left; width: 30%;">
<input ...>
</div>
<div style="float:left; width: 30%;">
Enter your birthdate.
</div>
This code actually works ok for me, but it just feels weird, not having something holding the rows together. I'm so accustomed to using tables, where you have a TR holding it together.
Is it better to wrap each row with a div, so that there's something solid holding the rows in line? I'm guessing it works either way, but I'm not too sure what's the best way.
From there, you can use label and div tags to separate your columns (as previously mentioned).
Just a point about your original idea of grouping the forms content into 3 separate columns... label / control / description. I would tend to avoid this method for a couple of reasons...
1. It's not (very) semantic. Each column/group has little meaning on its own. The natural grouping is (label + control + description). These 3 elements are related to each other and if anything should be grouped together. As you suggest, in a row.
2. You want the elements to line up in a row, but if these elements are separated into different containers/columns then the possibility of these elements not lining up is increased dramatically. What if your styles were disabled or an alternate stylesheet was used - it is likely that your label / control / description will become completely separated from each other! I suppose this comes back to creating semantic markup. If its semantic / laid out in a logical manner then the page should be at least readable and navigable even without any styles applied.
I guess that's really just one point split in two - think semantic. :)
I'll try that next time I think, although actual markup will be almost the same as in a <table>, which kinda defeats the object. I find that sometimes with CSS, why stop using a <table> if you have to have 3 <div> tags nested?
(rhetorical, please don't answer I've had that conversaion too many times!)