Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

html - Shall I use <section> tags inside <aside>?

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

See Question&Answers more detail:os

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

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...