0

我看到 HTML 列表用于网络上的各种事物,这让我对如何在语义上使用它们感到困惑。很明显,列表是为了列出文本或链接而创建的,但是幻灯片的图像呢,这感觉有些不对劲?

<ul class="slideshow">
  <li><img src="http://placehold.it/480x270" alt="Slide 1"></li>
  <li><img src="http://placehold.it/480x270" alt="Slide 2"></li>
  <li><img src="http://placehold.it/480x270" alt="Slide 3"></li>
</ul>

使用这样的 div 在语义上更正确吗?

<div class="slideshow">
  <div><img src="http://placehold.it/480x270" alt="Slide 1"></div>
  <div><img src="http://placehold.it/480x270" alt="Slide 2"></div>
  <div><img src="http://placehold.it/480x270" alt="Slide 3"></div>
</div>

我也看到过使用列表构建的表单,我不太确定那个以太。我查看了 W3C 文档,看起来它会验证,但它在语义上是否正确?

4

4 回答 4

3

是的。实际上,我已经看到了很好的论点,即一切都是一个列表,因此列出您的评论完全是语义上的方式......

ul 方法优于 div,因为它提供了比 div 更多的上下文。差别不大,但明显且重要。

于 2013-06-26T17:12:45.793 回答
0

在 div 元素上使用列表肯定更符合语义。只要您显示的是“事物”列表,那么使用列表元素就可以了。

于 2013-06-26T17:12:29.870 回答
0

在您开始进行流畅或响应式设计之前,这两种方式都可能没有问题。然后 ul 的想法就不再有意义了。

于 2013-06-26T17:12:57.917 回答
0

I think that unordered list is more semantic correct. Slideshows are lists of things displayed with different effects.

DIVs are tags with no semantic meaning, so, What would you choose?

Tip: Always fill the alt attribute for img tag.

于 2013-06-26T17:14:37.940 回答