【问题标题】:how to change color of header in HTML?如何更改 HTML 中标题的颜色?
【发布时间】:2020-04-30 12:54:29
【问题描述】:

这是我的 HTML 和 CSS,h1 标题显示为蓝色,而不是红色,我不知道为什么?以及如何解决?非常感谢

<!doctype html>

<h1>les planètes du système solaire <h1>
<h1><style type='text/css'>
body{
 color:red;
 background-color: black}
</style><h1>

<img src ='https://(jpeg link ....)'>
<h2>comme nous pouvons le constater<h2>
<h2><style type='text/css'>

body{
 color:blue;
 background-color:black}
</style><h2>

【问题讨论】:

  • 格式错误的 HTML 将无法为您带来任何好处...阅读 HTML 和 CSS。

标签: html css html5-canvas


【解决方案1】:
<h1 style="color: red;">My Heading</h1>

【讨论】:

    【解决方案2】:

    这是因为您不应该为每个标题元素声明样式,而最好只声明一次。

    您只需声明一次标题元素(如&lt;h1&gt;&lt;h2&gt;)并关闭标签。这是更新后的代码,我在顶部添加了一个 &lt;style&gt; 块,因此它适用于 HTML 文件中声明的所有元素。

    请阅读更多about document and website structure at MDN

    <!doctype html>
    <style type='text/css'>
      body {
        background-color: black
      }
      
      h1 {
        color: red;
      }
      
      h2 {
        color: blue;
      }
    </style>
    <h1>les planètes du système solaire</h1>
    
    <img src='https://(jpeg link ....)'>
    <h2>comme nous pouvons le constater</h2>

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-11-11
      • 1970-01-01
      • 2023-03-06
      • 1970-01-01
      • 1970-01-01
      • 2011-01-29
      • 2015-01-09
      • 1970-01-01
      相关资源
      最近更新 更多