I'm writing an ordered list. For each element in the list, I'd like to have two lines. One for the name of the item and another for a description of the item.
This is what I'm currently doing:
<ol>
<li>
<ul>
<li>Item one</li>
<li>An explanation of the item.&l开发者_StackOverflow社区t;/li>
</ul>
</li>
<li>
<ul>
<li>Item two</li>
<li>An explanation of the item.</li>
</ul>
</li>
</ol>
It seems like a lot to achieve what I was looking for. Does anyone know a quicker way to pull this off?
You may want to use a definition list (<dl>
) instead of the inner ul.
<dl>
<dt>Dog</dt>
<dd>A carnivorous mammal of the family Canidae.</dd>
</dl>
How about:
<ol>
<li>
<h3>Item one</h3>
<p>An explanation of the item.</p>
</li>
<li>
<h3>Item two</h3>
<p>An explanation of the item.</p>
</li>
</ol>
(Replace <h3>
with the appropriate level heading in that context in the document — or, if you’re using HTML5, wrap the <ol>
in a <section>
tag, and use <h1>
in place of <h3>
.)
Or do you really need an ordered list? If not, the definition list is the thing:
<dl>
<dt>Item one</dt>
<dd>An explanation of the item.</dd>
<dt>Item two</dt>
<dd>An explanation of the item.</dd>
</dl>
精彩评论