[Meta-note:] I was browsing the question page, getting really tired of ‘DIVS vs Tables’ ‘When to use tables vs DIVS’ ‘Are Divs better than Tables’ ‘Tables versus CSS’ and all the questions that ask THE SAME THING OMG PEOPLE but I would like to see all the ways people tackle the translation of the canonical example of ‘why you should give up and use tables’:
<table> <tr> <td> Name </td> <td> <input> </td> </tr> <tr> <td> Social Security Number </td> <td> <input> </td> </tr> </table>
Question: How to best (semantically, simply, robustly, fluidly, portably) implement the above without tables. For starters, I guess a naive implementation uses a fixed column width for the first column, but that can have iffy results for dynamically generated content. Including strengths/weaknesses of your approach in the answer would be nice.
P.S. Another one I wonder about a lot is vertical centering but the hack for that is covered pretty well at jakpsatweb.cz
EDIT: scunlife brings up a good example of why I didn’t think out the problem that carefully. Tables can align multiple columns simultaneously. The Question still stands (I’d like to see different CSS techniques used for alignment/layout) – although solutions that can handle his? more involved example definitely are preferred.
What I usually do is :
and in a CSS :
Of course, you’ll have to define the width according to your actual data 🙂
display: block, so that it can be assigned a size and be lined up.float: leftbecause Explorer does things a bit differentlybrso that there’s aclear: leftsomewhere, and I remember that putting it on the label didn’t work on some browser.Plus, with the
bryou get a nice formatting even if the browser does not support CSS 🙂