Brief moan
A flexible approach to this is the well-known gap in CSS for 15 years. That would have been resolved, but for the 15-year-old Firefox bug related to CSS 2, and perhaps it was possible if the tab-stops
specification, proposed 17 years ago, ever went underground. If you're interested, check out the updates below.
Limited solution
I found several different ways to do this without changing the markup using pseudo-elements. They all have significant flaws, but if you can reliably set the maximum width for dd
text, this is probably the best way:
dl { line-height: 1.3em; overflow: auto; width: 140px; } dt { float: left; width: 100%; } dd { float: right; margin-top: -1.3em; } dt:after{ content: ''; display: inline-block; width: 3.5em; }
Example: http://jsfiddle.net/Jordan/p4mMa/3/
Here the :after
pseudo-element takes up additional space in each dt
, forcing it to break into a new line if there is not enough space for the dd
element to fit at the end of the current one. (You will also need to reset your margins and padding on the elements, I left this for brevity.)
Alternatives
Other approaches that I considered included display: inline
in dt
and using the :before
pseudo-element with display: block
to break the line ( WebKit doesn't like it ) and the same approach, but using display: inline-block
and width: 100%
for the convenience of WebKit browsers (it works, but you have an indelible blank line before each dt
).
It should be noted that IE7 and IE8 are absent because they do not support pseudo-elements. If you want to progress, simply remove the negative marker in the dd
element in the conditional stylesheet, and prices will always be displayed on a separate line in these browsers.
UPDATE (2013-04-18): I know this is an old answer, but a recent conversation on Twitter reminded me of something that I think is worth mentioning. Another way to do this, which does not require determining the width for dd
: a little-known display: run-in
, in fact, allows you to consider a block-level element as the inline content of your next brother. The only trade-off is to port your dd
content using span; itβs also a relatively elegant solution that works in most modern browsers - and even in IE8!
Problem? A 15-year-old Firefox bug filed on Christmas Eve 1998 and is unlikely to be addressed any time soon.
This is understandable: the run-in
fields are "terribly underspecified" , there are not many use cases, and there are more important / useful things to work on. Nevertheless, it seems that he slipped through the cracks to some extent, and I cannot help but wonder if more people will use it with reliable support.
UPDATE (2013-11-13): This exact usage example was described in a list of suggested CSS extensions published by W3C in December 1998. Also, back in January 1997, Dave Raggett created a proposal for the tab-stops
property , which would work just fine here. Unfortunately, neither the precedent, nor the proposal received a large load.