Using CSS, how can I style the following:
<dl>
<dt>Mercury</dt>
<dd>Mercury (0.4 AU from the Sun) is the closest planet to the Sun and the smallest planet.</dd>
<dt>Venus</dt>
<dd>Venus (0.7 AU) is close in size to Earth, (0.815 Earth masses) and like Earth, has a thick silicate mantle around an iron core.</dd>
<dt>Earth</dt>
<dd>Earth (1 AU) is the largest and densest of the inner planets, the only one known to have current geological activity.</dd>
</dl>
so the content of the dt
show in one column and the content of the dd
in another column, with each dt
and the corresponding dd
on the same line? I.e. producing something that looks like:
Because I have yet to see an example that works for my use case, here is the most full-proof solution that I was able to realize.
Strangely enough, it doesn't work with
display: inline-block
. I suppose that if you need to set the size of any of thedt
elements ordd
elements, you could set thedl
's display asdisplay: flexbox; display: -webkit-flex; display: flex;
and theflex
shorthand of thedd
elements and thedt
elements as something likeflex: 1 1 50%
anddisplay
asdisplay: inline-block
. But I haven't tested that, so approach with caution.This works on IE7+, is standards compliant, and allows differing heights.
See the JSFiddle.
I've found a solution that seems perfect to me, but it needs extra
<div>
tags. It turns out that it is not necessary to use<table>
tag to align as in a table, it suffices to usedisplay:table-row;
anddisplay:table-cell;
styles:Depending on how you style the dt and dd elements, you might encounter a problem: making them have the same height. For instance, if you want to but some visible border at the bottom of those elements, you most probably want to display the border at the same height, like in a table.
One solution for this is cheating and make each row a "dl" element. (this is equivalent to using tr in a table) We loose the original interest of definition lists, but on the counterpart this is an easy manner to get pseudo-tables that are quickly and pretty styled.
THE CSS:
THE HTML:
I usually start with the following when styling definition lists as tables:
Assuming you know the width of the margin: