我应该使用< section> < aside>里面的标签? [英] Shall I use <section> tags inside <aside>?

查看:106
本文介绍了我应该使用< section> < aside>里面的标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有这样的标记:

 < aside> 
< div class =widget>
< h2>最新消息< / h2>
< ul> ...< / ul>
< a>更多新闻< / a>
< / div>
< div class =widget>
< h2>选择网站主题< / h2>
< input type =select/>
< / div>
< div class =widget>
< h2>时事通讯订阅< / h2>
< form> ...< / form>
< / div>
< div class =widget>
< h2>相关文章< / h2>
< ul> ...< / ul>
< / div>
< / aside>

这里的标签更合适:< div> < section>

部分应该只用于< article> tag并且永远不会在< aside>

解决方案

HTML 5规范并不禁止您在旁边的元素中使用部分元素。除了 元素被允许在其中包含流内容,并且包含部分元素。



然而, ,即使现在HTML5中的 div 元素应该是最后的手段的分段元素,使用部分


注意:section元素不是通用的容器元素。当仅仅为了样式或为了方便脚本而需要元素时,鼓励作者改为使用div元素。一般的规则是,section元素只有在元素的内容将在文档的大纲中明确列出时才是合适的。


现在,旁边的部分绝对不属于整个文档的大纲,因此对于您的问题的简短回答是使用 div 。或者,因为你看起来好像里面有四个项目,所以你可以考虑一个 ul 和四个 li s然后用规则替换ul li


Having a markup like this:

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

Which tag is more appropriate here: <div> or <section>?
Is section supposed to be used only inside <article> tag and never inside <aside>?

解决方案

The HTML 5 spec does not prohibit you from using the section element inside of an aside element. The aside element is allowed to have flow content inside, and that includes the section element.

However, even though the div element is now, in HTML5, supposed to be the sectioning element of "last resort", using section in this context goes against the intent of the element. From the spec we see:

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.

Now, little "sections" of an aside are definitely not something that belong in the outline of the entire document, so the short answer to your question is to use div. Alternatively, because your aside looks like it has four "items" inside, you might consider a ul with four lis and then style with the rule aside ul li.

这篇关于我应该使用&lt; section&gt; &lt; aside&gt;里面的标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆