HTML5 - 是
和
被认为是
我有一个侧边栏,其中包含最新新闻和随机博客文章等。
<nav id="sidebar">
<section id="latest_news">
<h1>
Latest News
</h1>
<h2>
<a href="/path/to/article">News Item 1</a>
</h2>
<p>
Truncated text from the news item in question
</p>
<a href="/news" title="View all news items" class="index">View all news items</a>
</section>
<section id="random_blog_post">
<h1>
Random Blog Post
</h1>
<h2>
<a href="/path/to/blog/post">Blog Post 1</a>
</h2>
<p>
Truncated text from the random blog post in question
</p>
<a href="/blog" title="View all blog posts" class="index">View all blog posts</a>
</section>
</nav>
如您所见,我的导航中包含部分、h1 和段落。
我只是想知道这是否允许或被认为是良好的做法。是否有更好的更多语义(或更少)的方法来标记和构建此类侧边栏内容?
I have a sidebar with latest news and random blog posts etc
<nav id="sidebar">
<section id="latest_news">
<h1>
Latest News
</h1>
<h2>
<a href="/path/to/article">News Item 1</a>
</h2>
<p>
Truncated text from the news item in question
</p>
<a href="/news" title="View all news items" class="index">View all news items</a>
</section>
<section id="random_blog_post">
<h1>
Random Blog Post
</h1>
<h2>
<a href="/path/to/blog/post">Blog Post 1</a>
</h2>
<p>
Truncated text from the random blog post in question
</p>
<a href="/blog" title="View all blog posts" class="index">View all blog posts</a>
</section>
</nav>
As you can see, I've got sections, h1's and paragraphs inside my nav.
I'm just wondering if this allowed or considered good practice. Is there a better more semantic (or less) approach to marking-up and structuring such sidebar content?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是的,这似乎是非常有效的 html5。 w3org 有一个示例,其中包含 h1 标签的导航。
Yes, this appears to be pretty valid html5. w3org have an example of navigation with h1 tags in it.
是的,您可以这样做,正如规范
与您的问题特别相关的引用:
和
Yes, you can do that, as also denoted in the spec
Quotes specifically relevant to your question:
and
实际上,您甚至可以将 h1 元素编写为 nav 元素的直接子元素,以便在文档的大纲中命名 nav 元素。
我建议阅读以下内容,了解标题和文档大纲的重要性:
http://dev.w3.org/html5 /spec-author-view/headings-and-sections.html#outline
您可以使用此在线工具检查文档的大纲:
http://gsnedders.html5.org/outliner/
问候。
Actually, you could even write an h1 element as a direct child of the nav element so that the nav element would be named in the document's outline.
I suggest this reading about the importance of headings and document's outline:
http://dev.w3.org/html5/spec-author-view/headings-and-sections.html#outline
You can check your document's outline with this on-line tool:
http://gsnedders.html5.org/outliner/
Regards.