Can I use <section>
tag inside unordered list?
I know, that <section>
represent a generic section of document. Usually we find heading inside.
So... I have list of products. Usually about 20 per page. Each element have:
heading,
short description (max 255 chars),
thumbnail, some details, button.
So each list item is something like section, "is a thematic grouping of content, typically with a heading"
.
Of course I don't use, <section>
to styling purpose.
I think, <section>
also could be here a wrapper for a list, and each element of list <article>
.
What is your opinion?
It depends upon context but usually the heading appears outside of the UL itself as a 'heading' for the list not an item of the list. <li> is an inline element, where headings are block elements. Placing block elements inside inline elements isn't something to do casually.
Sectioning elements can be nested inside one another as many times as is needed based on the content. The header and footer in a sectioning element can also contain sectioning elements.
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.
You create an unordered list using the ul tag. Then, you use the li tag to list each and every one of the items you want your list to include. tag.
Using a <section>
tag inside an <li>
tag validates (you can try this using the “Text Field” option on http://html5.validator.nu/), and the spec doesn’t seem to suggest you shouldn’t use it in this way (see http://dev.w3.org/html5/spec-author-view/the-section-element.html#the-section-element), so that seems fine to me.
The <article>
tag is meant for “self-contained compositions”. I’ve never been entirely clear what that means outside of several blog posts being listed on a single page, but I think product summaries sound like a decent fit for that too. So your second idea of a <section>
containing the entire list, and an <article>
for each product, probably sounds best.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With