Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
HTML5-are<;p>;及<;h1>;被认为是<;导航>;?_Html_Semantic Markup - Fatal编程技术网

HTML5-are<;p>;及<;h1>;被认为是<;导航>;?

HTML5-are<;p>;及<;h1>;被认为是<;导航>;?,html,semantic-markup,Html,Semantic Markup,我有一个侧边栏,上面有最新的新闻和随机的博客帖子等 <nav id="sidebar"> <section id="latest_news"> <h1> Latest News </h1> <h2> <a href="/path/to/article">News Item 1</a> </h2> <p> T

我有一个侧边栏,上面有最新的新闻和随机的博客帖子等

<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和段落


我只是想知道这是否允许或被认为是良好的做法。有没有更好的语义更丰富(或更少)的方法来标记和组织这样的侧边栏内容?

是的,这似乎是非常有效的html5。w3org有一个包含h1标记的导航列表。

是的,您可以这样做,如中所示

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

nav元素表示一个剖面 指链接到其他页面的页面,或 到页面中的各个部分:一个节 与导航链接

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


航行
你在我的主页上。北面躺着,从那里可以听到战斗的声音。向东
你可以看到一座大山,山上散落着许多垃圾。远山
你可以看到一个看起来像我的小人物,绝望地
涂鸦

西边有几个出口。一个有趣的出口被贴上了标签。再来一个 无聊的出口被贴上了标签

南面是一片阴暗潮湿的土地。蜘蛛网覆盖着它废弃的入口,在某一点上你可以 看到一只老鼠飞快地跑出了书页


实际上,您甚至可以编写一个h1元素作为nav元素的直接子元素,以便在文档的大纲中命名nav元素

我建议阅读标题和文件大纲的重要性:

您可以使用此在线工具检查文档的大纲:


问候。

非常感谢,这正是我所希望的。我必须给@BadDisplayName一个被接受的答案,因为他们的帖子比你的快1分钟:)再次感谢
 <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>