CSS div 样式表未反映在 html 中

问题描述 投票:0回答:1

尝试设置 div 标签的样式。这是我的代码。我已经翻阅了很多遍了,还是想不通。我的其他样式元素在页面上运行完美,但我似乎无法让 .header 工作。

简历.html

<html>

<head>
<title>test</title>
<body style="background-color:#eed9c4">
<link rel="stylesheet" href="stylesheet.css" />
</head>

<body>
<div class="header">
<center>
<h1>Resume</h1>
<h2>Julia</h2>
<br>
<img src="julia.jpg"></img>
</center>
</div>

...

样式表.css

<css>
<style>
body {
  font-family:serif;
  font-size: 83%
}
h1 {
  border-style: double;
  color: #bb6938;
  text-align: center;
}
h2 {
  color: #bb6938;
  margin-bottom: 0px;
  font-size: 100%
}
h3 {
  color: #bb6938;
  margin-bottom: 0px;
  font-size: 100%;
li {
  font-style: italic;
}
p{
  margin-top: 2px;
}

.header {
  background-color: blue
  color: #006747;
  z-index: 1;
  position: fixed;
  top: 0px;
  left: 0px;
  height: 210px;
  width: 100%;
}

</style>

</css>

试图确保我所有的支架都在那里并且所有东西都正确关闭。我只需要第二双眼睛。

html css
1个回答
0
投票

您的 HTML 和 CSS 中都有大量错误。最好不要使用已弃用的

HTML elements
,例如
center
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/center。 使用样式表来定位文本。我已经更新了您的 HTML 和 CSS,以实现我认为您可能正在寻找的目标。我只添加了
div
HTML。另外,删除
body
内的
head
行,我还在 CSS 中添加了背景颜色样式。

body {
  font-family: serif;
  font-size: 83%;
  background-color: #eed9c4;
}

h1 {
  border-style: double;
  color: #bb6938;
  text-align: center;
}

h2 {
  color: #bb6938;
  margin-bottom: 0px;
  font-size: 100%;
}

h3 {
  color: #bb6938;
  margin-bottom: 0px;
  font-size: 100%;
}

li {
  font-style: italic;
}

p {
  margin-top: 2px;
}

.header {
  background-color: blue;
  color: #006747;
  z-index: 1;
  position: fixed;
  top: 0px;
  left: 0px;
  height: 210px;
  width: 100%;
  text-align: center;
}
  <div class="header">
      <h1>Resume</h1>
      <h2>Julia</h2>
      <br>
      <img src="julia.jpg" />
  </div>

© www.soinside.com 2019 - 2024. All rights reserved.