HTML5 - 是

被认为是

发布于 2024-11-16 13:18:06 字数 961 浏览 1 评论 0原文

我有一个侧边栏,其中包含最新新闻和随机博客文章等。

<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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

九歌凝 2024-11-23 13:18:06

是的,这似乎是非常有效的 html5。 w3org 有一个示例,其中包含 h1 标签的导航。

Yes, this appears to be pretty valid html5. w3org have an example of navigation with h1 tags in it.

阳光下慵懒的猫 2024-11-23 13:18:06

是的,您可以这样做,正如规范

与您的问题特别相关的引用:

nav 元素代表一个部分
链接到其他页面的页面或
页面内的部分:一个部分
带有导航链接。

导航元素不必包含列表,它也可以包含其他类型的内容。在此导航块中,以散文形式提供链接:

 <nav>
 <h1>Navigation</h1>
 <p>You are on my home page. To the north lies <a href="/blog">my
 blog</a>, from whence the sounds of battle can be heard. To the east
 you can see a large mountain, upon which many <a
 href="/school">school papers</a> are littered. Far up thus mountain
 you can spy a little figure who appears to be me, desperately
 scribbling a <a href="/school/thesis">thesis</a>.</p>
 <p>To the west are several exits. One fun-looking exit is labeled <a
 href="http://games.example.com/">"games"</a>. Another more
 boring-looking exit is labeled <a
 href="http://isp.example.net/">ISP™</a>.</p>
 <p>To the south lies a dark and dank <a href="/about">contacts
 page</a>. Cobwebs cover its disused entrance, and at one point you
 see a rat run quickly out of the page.</p>
</nav>

Yes, you can do that, as also denoted in the spec

Quotes specifically relevant to your question:

The nav element represents a section
of a page that links to other pages or
to parts within the page: a section
with navigation links.

and

A nav element doesn't have to contain a list, it can contain other kinds of content as well. In this navigation block, links are provided in prose:

 <nav>
 <h1>Navigation</h1>
 <p>You are on my home page. To the north lies <a href="/blog">my
 blog</a>, from whence the sounds of battle can be heard. To the east
 you can see a large mountain, upon which many <a
 href="/school">school papers</a> are littered. Far up thus mountain
 you can spy a little figure who appears to be me, desperately
 scribbling a <a href="/school/thesis">thesis</a>.</p>
 <p>To the west are several exits. One fun-looking exit is labeled <a
 href="http://games.example.com/">"games"</a>. Another more
 boring-looking exit is labeled <a
 href="http://isp.example.net/">ISP™</a>.</p>
 <p>To the south lies a dark and dank <a href="/about">contacts
 page</a>. Cobwebs cover its disused entrance, and at one point you
 see a rat run quickly out of the page.</p>
</nav>
吲‖鸣 2024-11-23 13:18:06

实际上,您甚至可以将 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文