如果我有给定月份内发生的事件列表,例如:
October Events:
Oct. 8 - Community Dance Oct. 9 - Karaoke Night Oct. 10 - Pot-luck
最好的编码方法是什么——使用 UL、OL 还是其他东西?
无序列表
<h3>October Events</h3>
<ul>
<li>Oct. 8 - Community Dance</li>
<li>Oct. 9 - Karaoke Night</li>
<li>Oct. 10 - Potluck</li>
</ul>
有序列表
<h3>October Events</h3>
<ol>
<li>Oct. 8 - Community Dance</li>
<li>Oct. 9 - Karaoke Night</li>
<li>Oct. 10 - Potluck</li>
</ol>
如果我添加描述,您会改变看待它的方式吗?通过描述,我可能会这样:
<h3>October Events</h3>
<article>
<h4>Community Dance</h4>
<p class="date">Oct. 8</p>
<p>Description</p>
</article>
<article>
<h4>Karaoke Night</h4>
<p class="date">Oct. 9</p>
<p>Description</p>
</article>
<article>
<h4>Potluck</h4>
<p class="date">Oct. 10</p>
<p>Description</p>
</article>
那么,考虑到网络标准,编写事件列表的最语义方式是什么?
最佳答案
基于 W3C 维基 (http://www.w3.org/wiki/HTML_lists):
当尝试决定使用哪种类型的列表时,您通常可以通过提出两个简单的问题来决定:
- 我是否定义术语或关联其他名称/值对?
- 如果是,请使用描述列表。
- 如果不是,请不要使用描述列表 - 继续下一个问题。
- 列表项的顺序重要吗?
- 如果是,请使用有序列表。
- 如果不是,请使用无序列表。
在这里你应该使用:
<dl>
<dt>Oct. 8</dt>
<dd>Community Dance</dd>
<dt>Oct. 9</dt>
<dd>Karaoke Night</dd>
<dt>Oct. 10</dt>
<dd>Potluck</dd>
</dl>
关于html - 考虑到 Web 标准和语义,在编写事件列表时,我应该使用有序列表还是无序列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12786373/