gpt4 book ai didi

HTML5 大纲 – 带有标题围绕 Logo 的页眉

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:40:17 27 4
gpt4 key购买 nike

我一直想知道在我网站上的 Logo 周围使用标题标签的最佳做法是什么,尤其是使用 HTML5 分段标签时。

我在许多网站和论坛上了解到,如果我想在我的 Logo 周围添加标题,我应该执行以下操作:

<!DOCTYPE html>
<html>
[...]
<body>
<div id="outer-wrapper">
<header id="header" class="main-header clearfix">
<h1>
<img src="logo" src="[...]" alt="text goes here" />
</h1>
</header>
<div id="inner-wrapper">
[...]
</div>
</div>
</body>
</html>

但是现在,我网站上的每个页面都将 Logo 的 alt 属性中指定的文本作为其主标题,我可以想象,这并不理想。我的意思是,H1 标签旨在提供 «文档的主要主题»,但大多数时候不是我在 Logo 的 alt 标签上指定的文本。
但是,如果 Logo 的 alt 标记包含公司名称(因为它是公司 Logo ),我希望将它放在标题中(以赋予它一些相关性和重要性),只是不在 h1 标题中。

您认为以下是解决此问题的有效方法吗:

<!DOCTYPE html>
<html>
[...]
<body>
<div id="outer-wrapper">
<header id="header" class="main-header clearfix">
<h2>
<img src="logo" src="[...]" alt="text goes here" />
</h2>
</header>
<div id="inner-wrapper">
<article>
<h1>Main topic</h1>
</article>
</div>
</div>
</body>
</html>

最佳答案

这两个片段在语义上是相同的。如果使用分段元素,标题排名通常(但不总是)不再重要。

你可以自己测试一下,在 HTML5 outliner 中检查这两个片段(例如,在这个 online demo 中):

<body>
<h1>document heading</h1>
<article>
<h2>main content heading</h2>
</article>
</body>
<body>
<h2>document heading</h2>
<article>
<h1>main content heading</h1>
</article>
</body>

它们产生相同的轮廓:

1. document heading
1. main content heading

但是,HTML5 规范 encourages作者使用正确排名的标题元素,因此您应该坚持使用第一个片段。
HTML5 规范没有定义(第一个)h1 元素特别重要,或者它应该用于文档的“主要主题”。该规范定义了 rank, not importance .

我想你should use a heading for the logo如果此 Logo 代表站点(通常是这种情况),并且对 have this as the first heading 有意义(即,节段根 body 的标题)和 following sections should be in scope of it .

关于HTML5 大纲 – 带有标题围绕 Logo 的页眉,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32603923/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com