I'd like to use a definition list as simple as:
<dl>
<dt>name:</dt>
<dd>Tomas</dd>
<dt>address:</dt>
<dd>this is a very long wrapping address</dd>
<dt>age:<dt>
<dd>29</dd>
<dl>
to render something like:
name: Tomas
address: this is a very long
wrapping address
age: 29
The definition list seems semantically the best option here.
Using the new run-in display style will do the trick:
<style> dt { display: run-in; } </style>
But this isn't widely supported yet. How can I style my definition list for better cross-browser support (ie6 not necessary), without changing the html (currently I use display inline and add ugly br's) ?
Edit to clarify :
dt { clear: left; }
dd { float: left; }
won't work because it would render as:
name: Tomas
address: this is a very long
wrapping address
age: 29
The design specifies that these multi-line field should wrap to the start of line to preserve space.
I think this would work:
Another option that is useful is the
:after
pseudo-class. You could skip the colon on each of thedt
elements and have:This makes it more flexible and you can change that character across the list and website as a whole, or get rid of it if you felt like it.
To solve the wrapping problem you mentioned, you'll need to set widths on both the
dt
anddd
elements. Or, use a table, withth
for name/address etc andtd
for the "data". IMO a table is a semantically acceptable solution here - it is tabular data.You need to remove the default left margin from the dd.
Well, you could simply let dt float: left
or else let dt display inline:
I think this (uncomment first line to test for small width):
You could just float the dd to the left of the previous element like so.
You could also add a width attribute to either for extra alignment.