html - 嵌套 HTML5 部分标签

标签 html

这是使用 <section> 的正确方法吗?标签?

<section id="container">
   <section id="outer">
      <section id="inner">
      </section>
   </section>
</section>

我正在考虑是否应该只使用一个部分 ID,而将其他两个部分保留为 div?

最佳答案

如果您只是使用这些元素将事物放置在某个位置/样式事物,那么您可能应该使用 div。

部分实际上是用于将属于一起的内容分组 - 你真的不应该有一个没有标题(H1 或类似)元素的部分来描述该部分包含的内容......我认为过去有几个人犯过类似的错误:

http://html5doctor.com/the-section-element/

来自规范:

NOTE: The section element is not a generic container element. When an element is needed for styling purposes or as a convenience for scripting, authors are encouraged to use the div element instead. A general rule is that the section element is appropriate only if the element's contents would be listed explicitly in the document's outline.

话虽如此,嵌套节元素是完全可以接受的。也许是这样的:

<section>
    <h1>Portishead</h1>
    <p>Portishead are a cool band from Bristol</p>
    <section>
        <h1>Dummy (album)</h1>
        <p>some info....</p>
        <img src="..." />
    </section>
    <section>
        <h1>Portishead (album)</h1>
        <p>some other info info....</p>
        <img src="..." />
    </section>
</section>

关于html - 嵌套 HTML5 部分标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7041283/

相关文章:

javascript - 在页面加载时调用上面定义的 Javascript 方法

html - wkwebview run local html (in document) Received an unexpected URL from the web 进程

javascript - 如何保护 HTML5+PhoneGap 移动应用程序中的数据?

html - 如何设置iframe以填充页面宽度?

javascript - 如何打乱 HTMLCollection

javascript - 如何循环或迭代相同组件的 html 代码

javascript - 存储十六进制 HTML 颜色作为数值转换返回不同的颜色

javascript - Bootstrap 3 中的导航栏下拉菜单

html - rel-canonical prev/next 当 head 不能被写入时

javascript - 如何让我的 Phaser 游戏射出不止一支箭?