I want to make an ordered definition list. Should I nest an <ol> in a <dl>, or the other way around?
i.e.
<h4>Bike Descriptions</h4>
<dl>
<ol>
<li>
<dt>Giant Bikes</dt>
<dd>Bikes that are very sturdy and reliable.</dd>
</li>
<li>
<dt>Walmart Bikes</dt>
<dd>Bikes that are crummy and heavy.</dd>
</li>
</ol>
</dl>
Or nest the <dl> within <ol> or even within each <li>?
The docs don't seem to say.
The <ol> tag defines an ordered list. An ordered list can be numerical or alphabetical. The <li> tag is used to define each list item.
Lesson Summary As we learned, HTML provides you with three types of lists: Ordered lists, which have an inherent order and each item is numbered. Unordered lists, which have no inherent order and each item is bulleted. Description lists, which contain a list of terms and descriptions for each term.
According to that documentation, the only elements a <dl> may contain are <dt> and <dd>:
Content model:Zero or more groups each consisting of one or more
dtelements followed by one or moreddelements, optionally intermixed with script-supporting elements.
Thus, your example code is invalid HTML. The only valid way to nest dl and ol/ul is in the order ol/ul > li > dl > dt+dd:
<h4>Bike Descriptions</h4>
<ol>
<li>
<dl>
<dt>Giant Bikes</dt>
<dd>Bikes that are very sturdy and reliable.</dd>
</dl>
</li>
<li>
<dl>
<dt>Walmart Bikes</dt>
<dd>Bikes that are crummy and heavy.</dd>
</dl>
</li>
</ol>
Your example is not a valid HTML tag. Perhaps you would like to do something like this.
<h4>Bike Descriptions</h4>
<ul>
<li>
<dl>
<dt>Giant Bikes</dt>
<dd>Bikes that are very sturdy and reliable.</dd>
</dl>
</li>
<li>
<dl>
<dt>Walmart Bikes</dt>
<dd>Bikes that are crummy and heavy.</dd>
</dl>
</li>
</ul>
Then you can add style to your CSS to fix the layout.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With