How to correctly use “section” tag in HTML5?

前端 未结 6 1441
囚心锁ツ
囚心锁ツ 2020-12-02 04:59

I\'m trying to build a layout in HTML5 and after reading several different articles I\'m just confused. I\'m trying to get some input on how it should be used.

Below

6条回答
  •  無奈伤痛
    2020-12-02 05:08

    My understanding is that SECTION holds a section with a heading which is an important part of the "flow" of the page (not an aside). SECTIONs would be chapters, numbered parts of documents and so on.

    ARTICLE is for syndicated content -- e.g. posts, news stories etc. ARTICLE and SECTION are completely separate -- you can have one without the other as they are very different use cases.

    Another thing about SECTION is that you shouldn't use it if your page has only the one section. Also, each section must have a heading (H1-6, HGROUP, HEADING). Headings are "scoped" withing the SECTION, so e.g. if you use a H1 in the main page (outside a SECTION) and then a H1 inside the section, the latter will be treated as an H2.

    The examples in the spec are pretty good at time of writing.

    So in your first example would be correct if you had several sections of content which couldn't be described as ARTICLEs. (With a minor point that you wouldn't need the #primary DIV unless you wanted it for a style hook - P tags would be better).

    The second example would be correct if you removed all the SECTION tags -- the data in that document would be articles, posts or something like this.

    SECTIONs should not be used as containers -- DIV is still the correct use for that, and any other custom box you might come up with.

提交回复
热议问题