gpt4 book ai didi

html - 页脚可以有页眉标签吗?

转载 作者:搜寻专家 更新时间:2023-10-31 08:17:55 25 4
gpt4 key购买 nike

我已经讨论过关于页眉和页脚的问题。由于 HTML5 提供了页眉、页脚、内容元素,我认为每个页面应该使用一次。我在下面的片段中陈述了它们。

<!-- My understanding -->
<header>
<!-- code goes here -->
</header>
<content>
<!-- code goes here -->
<!-- code goes here -->
</content>
<footer>
<!-- code goes here -->
</footer>

很少有人有像下面这样的页眉、页脚元素方法。

<!-- People understanding -->
<header>
<!-- code goes here -->
</header>
<content>
<!-- code goes here -->
<!-- code goes here -->
</content>
<footer>
<header>
<!-- They also use <header> in footer. -->
</header>
<!-- code goes here -->
</footer>

header 可以用在 footer 元素中吗?换句话说,您建议如何构建 HTML 结构?

最佳答案

不,这是无效的。

header 元素表示内容的标题,但是 header 元素不能是footer< 的后代 元素。

HTML5 specificationfooter 部分指出 footer 元素是:

Flow content, but with no header, footer, or main element descendants.

如果您将以下代码粘贴到 W3's HTML Validator 中,您将收到以下错误:

Line 8, Column 20: The element header must not appear as a descendant of the footer element.

<!doctype html>
<html>
<head>
<title>Title</title>
</head>
<body>
<footer>
<header>
</header>
</footer>
</body>
</html>

忽略无效的 content 元素,您的第一个示例是有效的,您应该坚持使用它。

关于html - 页脚可以有页眉标签吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26357007/

25 4 0