html - 我应该在 <aside> 中使用 <section> 标签吗?

标签 html tags semantics semantic-markup

有这样的标记:

<aside>
    <div class="widget">
        <h2>Latest news</h2>
        <ul>...</ul>
        <a>more news</a>
    </div>
    <div class="widget">
        <h2>Choose site theme</h2>
        <input type="select" />
    </div>
    <div class="widget">
        <h2>Newsletter subscription</h2>
        <form>...</form>
    </div>
    <div class="widget">
        <h2>Related articles</h2>
        <ul>...</ul>
    </div>
</aside>

这里哪个标签更合适:<div><section> ?
section 应该只在 <article> 内部使用吗?标签,从不在里面 <aside>

最佳答案

HTML 5 规范不禁止您在 aside 元素内使用 section 元素。 aside允许元素在内部包含流内容,包括 section 元素。

然而,尽管 div 元素现在在 HTML5 中被认为是“最后手段”的分段元素,但在此上下文中使用 section 违背了元素的意图。从规范中我们看到:

Note: The section element is not a generic container element. When an element is needed only 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.

现在,aside 的小“部分”绝对不属于整个文档的大纲,因此对您的问题的简短回答是使用 div。或者,因为你的 aside 看起来像里面有四个“项目”,你可能会考虑一个带有四个 liul ,然后使用规则 aside ul li 设置样式

关于html - 我应该在 <aside> 中使用 <section> 标签吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19175668/

相关文章:

javascript - 在简单的登录表单中单击按 Enter 键

tags - 在 GitHub Actions 中添加基于日期的标签

css - 为什么我的 Div 标签被推到左边几个像素?

java - "code against"或 "resolve against"是什么意思?

c - Ruby 的最大函数顺序如何重复?

java - 当用户摆弄 html 范围 slider 时如何更改内容(文本)?

javascript - 如何让一个 float 的div消耗所有的鼠标滚动事件

html - Bootstrap Jumbotron 停靠图像到底部

xml - 与元素类型 "xsi"关联的属性 "xsi:schemaLocation"的前缀 "beans"未绑定(bind)。在tomcat上运行spring时

python - 如何在 python 中创建基本的语义搜索