Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
829 views
in Technique[技术] by (71.8m points)

css - Using section element for stylistic layout and wrappers

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

  • div element:

    The div element has no special meaning at all.

  • section element:

    The section element represents a generic section of a document or application. A section, in this context, is a thematic grouping of content, typically with a heading.

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

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.

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

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...