【问题标题】:HTML5 Headings not acting as they shouldHTML5 标题没有发挥应有的作用
【发布时间】:2017-03-01 12:34:41
【问题描述】:

所以我开始为学校作业编写 HTML 代码。我想使用 HTML5 语义,例如 <section><article> 等。但是当我放置在这些标签中时,我遇到了一些关于标题大小的特殊情况(见下文)。然后我继续将语义更改回只有 HTML,即只有 <div>,并且标题工作正常。我将发布一些屏幕截图以帮助澄清情况。

首先是带有<div>标签的代码

<!DOCTYPE html>
<html>
<head>
    <title>
        Curriculum Vitae
    </title>
</head>
<body>
<div>
    <h1>Curriculum Vitae</h1>
</div>
<div>
    <h2>Personal Information</h2>
    <ul>
        <ol><strong>Name: </strong>Haroon Rasheed Ramay</ol>
    </ul>
</div>
</body>
</html>

The heading sizes appear to work properly within in the div tags

接下来是使用 HTML5 语义的代码

<!DOCTYPE html>
<html>
<header>
    <title>
        Curriculum Vitae
    </title>
</header>
<body>
<article>
    <section>
        <h1>Curriculum Vitae</h1>
    </section>
    <section>
        <h2>Personal Information</h2>
        <ul>
            <ol><strong>Name: </strong>Haroon Rasheed Ramay</ol>
        </ul>
    </section>
</article>
</body>
</html>

Note here in this picture I have used the same heading tags for Curriculum Vitae and Personal Information but the heading sizes seemed to have switched?!

请其他人验证这似乎只是我的问题,还是我以完全错误的方式使用 HTML5 语义标签导致标题的特殊行为?

附:任何 HTML 文档或教程的链接都很棒(目前我正在在线学习 udacity 和 w33schools 的课程以及在学校作为一门学科)

【问题讨论】:

    标签: html semantics html-heading


    【解决方案1】:

    您混淆了headheader 标签。它们非常不同。

    每个 HTML 页面都必须有一个 head 标记(尽管浏览器通常会在缺少标记时插入一个)。

    header 标签用作页面内容的标题、标题或类似内容。它是可选的,将在 inside body 标签中;可能在article 或其他一些“主要内容标签”之前。

    【讨论】:

    • 感谢您对
      的澄清,而 并没有意识到我正在这样做。但是,它仍然没有将标题标签的特殊行为改回应有的方式。
    • @HaroonRamay 看看这个答案,好像是浏览器设置了自己的风格stackoverflow.com/a/22898717/3711733
    • @mguida 是的,您链接的情况似乎是这样。现在我因为在发布之前没有正确搜索而感到非常愚蠢。尽管我还想纠正一些我还没有完全理解的问题,但我会点击 Benio 在您的链接中提供的文档 (w3c.github.io/html/rendering.html#sections-and-headings) 以完全了解发生了什么。再次感谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-01-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多