I would like to show several rows of data which each have a title and some data on the same row. This question has definitely been answered on SO (i.e. How to style dt and dd so they are on the same line?), however, it doesn’t seem to work for me. The following seems to work, except when a DD has not content in which a fixes it. I am interested it IE7+. Is how I am doing this correct? Thanks
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Untitled</title>
<style>
dl {width: 395px; font-size:12px}
dd,dt {padding-top:5px;padding-bottom:5px;}
dt {float:left; padding-right: 5px; font-weight: bolder;}
/* dd {padding-left: 5px;} Does not work */
</style>
</head>
<body>
<dl>
<dt>DT Element 1:</dt><dd>DD Elem 1</dd>
<dt>DT Second Element:</dt><dd>DD Element Two</dd>
<dt>DT Elem 3:</dt><dd></dd>
<dt>DT Element 4:</dt><dd>DD Elem 4</dd>
<dt>DT Fifth Element:</dt><dd> </dd>
<dt>DT Elem 6:</dt><dd>DD Element Six</dd>
</dl>
</body>
</html>
Your problem is that an empty
ddis not generated and leaves an empty space (height:0px).If you can, yes, simply put a
nbsp;inside any empty element. It’s the simplest solution that will work cross-browser.A simple, pure css fix would be like this :
But it adds a dot after each definition…
You can also simply set a min-height on your dd :
(dt and dd min-height needs to be the same!)
demo
…You’ll probably run into issue if your
dtheight is not regular (if it’s sometime on 2 lines for example).