如何更改HTML标头的颜色?

时间:2020-01-13 19:24:39

标签: html css html5-canvas

这是我的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>

2 个答案:

答案 0 :(得分:3)

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

您只需要声明一次标题元素(例如<h1><h2>)并关闭标签。这是更新的代码,我在顶部添加了一个<style>块,因此它适用于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>

答案 1 :(得分:2)

<h1 style="color: red;">My Heading</h1>