本文介绍了使用section元素进行样式布局和封装的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我经常使用div来进行样式布局(没有内容的标记,特别注重设计)和网站上的封装。

I often use divs for stylistic layouts(pieces of markup with no content, specifically focused on the design) and wrappers on sites. With that said, Why should sections not be used for this task?

一个段本身是否有固有的语义意义,阻止它用于包装器?

Does a section by itself have an inherent semantic meaning that discourages it being used for wrappers?

几乎我使用的每一个页面都有一些封装或某种风格的布局。

Almost every page I use has some wrapper or stylistic layout of some sort. Wanting to phase out divs, I wonder, if sections can be used for wrappers and still be semantically correct.

推荐答案

是的,我们希望逐步淘汰div,我想知道,如果这些部分可以用于包装器, 元素具有固有语义。请参阅HTML5规范中的定义:

Yes, the section element has an "inherent semantic meaning". See the definitions in the HTML5 spec:




  • 要了解此含义是什么,请参阅对问题。

    To understand what this meaning is about, see my answer on the question HTML5 section tag meanings?.

    不是使用作为CSS / JS的包装器是:每个在。

    The most important argument for not using section as a wrapper for CSS/JS is: each section creates an entry in the outline of your document.

    不要使用作为包装器。请改用 div (分别 span )。

    Don’t use section as a wrapper in the way you described it. Use div (resp. span) instead.

    如果适当地使用部分,您当然可以使用它作为选择器另外,CSS / JS,因此您不需要为此添加另一个 div

    If you use section appropriately, you can of course use it as selector for CSS/JS in addition, so you don’t need to add another div for this.

    这篇关于使用section元素进行样式布局和封装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

    10-27 02:42