我试图组织一个页面布局,在页面顶部有一个大的“英雄”部分,其中包括页面标题。
据我所见,英雄应该独立成自己的<section>
.但是根据 W3 验证器,<section>
不应包含 <h1>
标记,因为它是顶级标题。
我应该如何在英雄中显示页面标题?
<body>
<header>
<nav>
</nav>
</header>
<main>
<section class="hero">
<h1>Page title</h1>
</section>
<section class="content">
<p>The page's content</p>
</section>
</main>
<footer>
</footer>
</body>
最佳答案
搜索机器人考虑 h1
元素作为页面内容所属的重要排名指标以及它如何与页面等其他排名指标相关title
标签,meta
标签和其他模式 - 所以如果排名很重要,永远不要排除 h1
考虑使用 <header>
改为标记:
<header>
<h1>Main Page Title</h1>
<img src="mdn-logo-sm.png" alt="MDN logo">
</header>
The element is not sectioning content and therefore does not introduce a new section in the outline. That said, a header element is intended to usually contain the surrounding section's heading (an h1–h6 element), but this is not required.
来源:<header>
HTML | MDN
关于css - HTML5 语义 - 在一个部分中包含页面标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46345007/