有这样的标记:
<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 看起来像里面有四个“项目”,你可能会考虑一个带有四个 li
的 ul
,然后使用规则 aside ul li 设置样式
。
关于html - 我应该在 <aside> 中使用 <section> 标签吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19175668/