Is semantically correct to use a header, footer o main elements inside a dialog component in Html5?.
I want to build a complex modal view with options about articles in my main page content. I am wondering if is correct use html5 as follows
<dialog>
<header>
<h1>Title</h1>
<button> Save </button>
</header>
<main>
<!--modal view options-->
</main>
</dialog>
Only the <main> tag shouldn't be there.
As copied from W3schools:
The header element represents a container for introductory content or a set of navigational links.
And:
You can have several header elements in one document.
This applies to the header and the footer.
but then there is this:
There must not be more than one main element in a document. The main element must NOT be a descendant of an article, aside, footer, header, or nav element.
So, to say it in a short way:
you can use multiple <header> and <footer> tags in your document, but you're better of using a <div> instead of your <main>
Tl;dr
Using header, footer or main in the dialog element for the purpose of describing this dialog's content is not semantically correct.
About header and footer
Only Sectioning content elements (or body) define a semantic scope that is applied to header and footer. dialog is not a sectioning content (source). So, header and footer placed within dialog will describe the closest sectioning content or body, not a dialog itself.
About main element
There are 3 important rules to remember when using main element (source):
it should be used only to represent the dominant contents of the document (dialog's content is not likely to be the dominant content),
there can be only one main element without hidden attribute on the webpage at the same time (which means you would need to add hidden attribute on your general main page element),
main element ancestors can only be html, body, div or form elements without an accessible name. main cannot be contained within anything else, including autonomous custom elements.
So, 3rd point makes it impossible to use main element inside of a dialog. And 1st and 2nd make it really hard.
Solution
Good solution in this case would be to either drop using of those elements or to wrap dialog's content with a section element to be able to provide semantic header and footer.
<dialog>
<section>
<header><!-- header content --></header>
<div>
<!-- modal content -->
</div>
<footer><!-- footer content --></footer>
</section>
</dialog>
Related
I have an article template in which I want the title to run the full width of the page (12 cols), and then the text itself to fall in below with an adjacent sidebar (8 and 4 cols respectively). The problem is that I can't get the sidebar to nest alongside the article body without placing it within the article section.
My question is: is it bad practice to move the sidebar element up so it falls within the article section, and thus sits nicely on the right next to the main content, but below the title?
The markup would look something like this:
<article>
<header>
PAGE/POST TITLE
</header>
PAGE/POST CONTENT
<div class="sidebar">
SIDEBAR CONTENT
</div>
</article>
The article element, just like any other HTML element, should only contain content that conforms to the element’s definition.
Including navigation doesn’t seem to be appropriate, unless it’s the navigation for the article itself (like a table of contents or similar), in which case you should use the nav element.
While there is the aside element, which would allow to markup separate content inside of article, this content still has to be
[…] tangentially related to the content around the aside element
As the title says, do I have to use these new tags in a DIV or are they basically DIVs themselves?
This is how each of the major HTML5 tags can/should be used:
section – Used for grouping together thematically-related content. Sounds like a div element, but it’s not. The div has no semantic meaning. Before replacing all your div’s with section elements, always ask yourself: “Is all of the content related?”
aside – Used for tangentially related content. Just because some content appears to the left or right of the main content isn’t enough reason to use the aside element. Ask yourself if the content within the aside can be removed without reducing the meaning of the main content. Pullquotes are an example of tangentially related content.
header – There is a crucial difference between the header element and the general accepted usage of header (or masthead). There’s usually only one header or ‘masthead’ in a page. In HTML5 you can have as many as you want. The spec defines it as “a group of introductory or navigational aids”. You can use a header in any section on your site. In fact, you probably should use a header within most of your sections. The spec describes the section element as “a thematic grouping of content, typically with a heading.”
nav – Intended for major navigation information. A group of links grouped together isn’t enough reason to use the nav element. Site-wide navigation, on the other hand belongs in a nav element.
footer – Sounds like its a description of the position, but its not. Footer elements contain informations about its containing element: who wrote it, copyright, links to related content, etc. Whereas we usually have one footer for an entire document, HTML5 allows us to also have footer within sections.
<header>
The <header> element represents a container for introductory content or a set of navigational links.
A element typically contains:
one or more heading elements ( - ) logo or icon authorship information You can have several elements in one document.
Note: A <header> tag cannot be placed within a , or another element.
<nav>
The <nav> tag defines a set of navigation links.
Notice that NOT all links of a document should be inside a <nav> element. The <nav> element is intended only for major block of navigation links.
<aside>
The <aside> tag defines some content aside from the content it is placed in.
The aside content should be related to the surrounding content.
<section>
The <section> tag defines sections in a document, such as chapters, headers, footers, or any other sections of the document.
I have a <nav> element where its title is wrapped in a <header>. However, this <header> is the last element in the <nav>. Is this a good practice?
I looked at the W3C's definition of <header>, and it has this to say:
The header element represents introductory content for its nearest ancestor sectioning content or sectioning root element. A header typically contains a group of introductory or navigational aids.
When the nearest ancestor sectioning content or sectioning root element is the body element, then it applies to the whole page.
This doesn't explicitly say where in its nearest ancestor it should be placed, but implies it should be the first (or topmost) element.
Here's a screenshot of my current mockup:
Note that this is not the final design and the element is position: fixed to the top of the viewport
If you take a look at the standard it doesn't say you cant do this. It only says the header element cant be a decendant of an address or footer element. So go for it.
header - http://www.w3.org/TR/html-markup/header.html
nav - http://www.w3.org/TR/html-markup/nav.html
Generally speaking it would make sense for the nav element to be a child of the header element, or for the two to be separate.
I want to make use of the semantics of the html grouping elements as much as possible.
I am struggling with the right element name for a viewport that centers my whole page in the middle of the screen (only horizontally).
My current solution is this:
<section id="viewport">
<header>
<nav>
<ul>
<li id="home">Home</li>
<li id="about">About me</li>
<li id="contact">Contact</li>
</ul>
</nav>
</header>
<main data-ng-controller="shell as vm">
<img alt="logo" src="/content/images/midbody.png" />
<aside data-ng-show="vm.isBusy" class="page-splash dissolve-animation">
<div data-cc-spinner="vm.spinnerOptions"></div>
</aside>
<article data-ng-view class="contentpage"></article>
</main>
<footer>
<div id="footer">Webdesign by Patrick Peters</div>
</footer>
</section>
The html elements are about semantic. While footer, header or aside imply somehow that header is at the beginning footer at the end and aside somewhere else, they main purpose is not about telling how their layout is, but to describe the importance and what they are about.
Because of that there is no equivalent for a centered element, because centered is only a visual information. And the visual representation belongs to css.
So if section fits use section. You have a header and a footer so it is a section somehow, but as it is the whole page that is represented by body there is no real need to wrap it into a section (it does not make the structuring clearer). If it has no semantic meaning you can stay with div as an anonymous container.
whatwg: section
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.
Examples of sections would be chapters, the various tabbed pages in a tabbed dialog box, or the numbered sections of a thesis. A Web site's home page could be split into sections for an introduction, news items, and contact information.
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.
whatwg: body
The body element represents the main content of the document.
The default layout page I get in a MVC razor has a problem with the section tag being smaller than its contents. The issue is I have a large table inside of it, and it is running out of the section, rather than the section simply becoming wide enough to fit it. I have recreated the issue in jsFiddle. You can see that the blue box is much thinner than the red box. The blue section being the initial size of the window, but if you scroll right, then you see the table is wider than the section.
How do I get the section to widen to match the size of its contents?
<div class="page">
<section id="main" style="background:blue;height:50px">
<table style="width:1000px; overflow:auto;background:red">
<tr><td>lkjlkjlkjlkjjhgjhgjhgjgjhgjhg</td></tr>
</table>
</section>
<footer>
</footer>
</div>
http://jsfiddle.net/sDG8n/1/
Float the section to the left
<section id="main" style="float:left;background:blue;height:50px">
Try putting the overflow:auto on the section instead of on the table.
The Spec says you're doing it wrong:
The section element represents a generic document or application
section…The section element is not a generic container element. When
an element is needed for styling purposes or as a convenience for
scripting, authors are encouraged to use the div element instead
In other words: Use a DIV.