【问题标题】:Why do CSS instructions not recognize header classes? [closed]为什么 CSS 指令不能识别标头类? [关闭]
【发布时间】:2019-08-05 19:29:14
【问题描述】:

为什么 CSS 文件不能根据其类来理解对标头的引用?人们会期望以下两个 CSS 命令将每一行设置为不同的颜色。相反,我们会遇到意想不到的行为。

h1.red{
    color: red;
}
h1.blue{
    color:blue;
}
<html>
    <head>
        <link rel="stylesheet" type="text/css" href="style.css">
    </head>
    <body>
        <h1 class='red'>This text should be red.</h1>
        <h2 class='blue'>This text should be blue.</h2>
    </body>       
</html>

有没有办法区分 CSS 中的多个 header 标签?

【问题讨论】:

  • h2.blue { color: blue; } 只是一个错字还是实际问题?您可以简单地使用 .blue { color: blue; } 来避免标签更改问题。顺便说一句,红色很有效。
  • 这只是一个错字。我犯了一个明显的错误。 (语法错误)我应该删除这个问题吗?
  • 我会关闭/删除它
  • 如何关闭问题? @MarkSchultheiss
  • 应该有一个“删除”按钮来删除它,这是我会做的

标签: html css html-heading


【解决方案1】:

您正在尝试使用 h1 选择器修改 &lt;h2&gt; 元素。试试

h1.red{
    color: red;
}
h2.blue{
    color:blue;
}

【讨论】:

    【解决方案2】:

    您错误地添加了一个 h2 而不是两个 h1。

    【讨论】:

      猜你喜欢
      • 2019-03-26
      • 1970-01-01
      • 2012-04-26
      • 1970-01-01
      • 2014-01-02
      • 1970-01-01
      • 1970-01-01
      • 2018-03-01
      • 1970-01-01
      相关资源
      最近更新 更多