标题/标题位于文章标签外部的布局的最佳 HTML5 结构



我有一个布局,让我可以选择:

  1. 在文章标签中包含侧边栏,即使它不是特定于文章的
  2. 标题在文章标签之外

目前我在文章标签之外有标题,但验证者告诉我 itemprop="headline" 不是任何项目的一部分。

构建

它的最佳方法是什么?是否有将标题与文章相关联的for属性?

如果您想知道哪种类型的布局会迫使我做出此选择,它是一个全角标题部分,然后是下面的文章和侧边栏。

编辑

简化代码

<div class="page-wrap">
    <header class="article-header" itemprop="headline">
        <h1>This heading section spans the width of the page</h1>
    </header>
    <div class="content-wrap">
        <nav class="submenu">
            <p>The submenu is here in the markup so that it appears above the content on mobiles, but it gets pulled to the side on wider screens.</p>
        </nav>
        <article class="content">
            <p>Article content...</p>
        </article>
        <aside class="sidebar">
            <p>This sidebar is not related specifically to the article on the page.</p>
        </aside>
    </div><!-- .content-wrap -->
</div><!-- .page-wrap -->

无法指定它所属部分之外的标题。

所以如果h1article内容的标题,它必须是article的子项。否则,文档大纲将不正确(→article会创建一个多余/不必要的条目):

1. This heading section spans the width of the page
  1.1 (implicit heading from the 'article' element)

注意:如果子菜单(nav)用于导航article(例如,像维基百科文章的ToC),它也应该是article的子菜单。

而不是用这个包装你的页面:

<div class="page-wrap">...</div>

把它包装成这样:

<body>...</body>

我从来没有使用过itemprop="headline"。这是一个新的HTML5属性。许多浏览器不支持它。请参阅此处 http://en.wikipedia.org/wiki/Microdata_(HTML)#Support

这是一篇关于微数据的文章(这就是itemprop)。 http://html5doctor.com/microdata/

这个 Stackoverflow 问题解释了为什么你不能添加对微数据的 Javascript 支持。使用 JavaScript 添加微数据

所以你可以只使用WAI ARIA。它的工作原理是这样的:http://mcdlr.com/wai-aria-cheatsheet/

为什么有一个子菜单?主菜单在哪里?如果您的标题不占用太多空间,则应在标题中包含主菜单。

最新更新