gpt4 book ai didi

html - 考虑到 Web 标准和语义,在编写事件列表时,我应该使用有序列表还是无序列表?

转载 作者:行者123 更新时间:2023-12-02 05:28:06 24 4
gpt4 key购买 nike

如果我有给定月份发生的事件列表,例如:

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 Wiki (http://www.w3.org/wiki/HTML_lists):

在尝试决定使用哪种类型的列表时,您通常可以通过问两个简单的问题来决定:

  1. 我是在定义术语还是在关联其他名称/值对?
    • 如果是,请使用描述列表。
    • 如果不是,请不要使用描述列表——继续下一个问题。
  2. 列表项的顺序重要吗?
    • 如果是,请使用有序列表。
    • 如果否,则使用无序列表。

在这里你应该使用:

<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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com