如何使头部和body颜色不同



我想让头部和身体变得不同,彼此独立。正因为如此,我想要不同的背景色,但我一直没能做到。

如果有人知道我如何让头部和身体的造型看起来与众不同,请告诉我。我已经包含了我在下面的网站上使用的代码。

<html>
    <head>
        <p>Hi there!</p>
    </head>
    <body>
        <style>
            body {
                background-color: lightblue;
            }
            head {
                background-color: lightgreen;
            }
        </style>
        <p>Hi there!</p>
    </body>
</html>

输出图像:

页面输出

head标记用于描述文档的元数据和重要信息。显示在那里的东西是看不见的。

您的p标签应该在body标签之下,而不是在head标签之下。

你想的可能是你网页的header部分,它包含在你的身体标签下。

此外,css声明应该在它们自己的单独文件中进行。以下是您的代码应该看起来像

<html>
  <head>
      <link rel="stylesheet" href="styles.css">
  </head>
  <body>
    <header>
    </header>
    <p>Hi there!</p>
  </body>
</html>

样式.css

body {
  background-color: lightblue;
}
header {
  background-color: lightgreen;
}

最新更新