我的CSS背景不会显示

时间:2018-03-05 17:34:07

标签: html css

我检查并仔细检查了语法,但我不确定为什么我的CSS背景无法加载:

 body { 
  font-family: cursive,serif; 
  background: url("../images/background.jpeg") no-repeat center center;
  background-attachment: fixed;
  background-size: cover;
}

文件夹结构

--index.html
--style.css
--images
  |____ background.jpeg

1 个答案:

答案 0 :(得分:3)

CSS中有两个问题:

  • .body用于选择body类的元素(例如<div class="body"></div>)。如果您确实要将CSS添加到<body>,请删除开头的点。
  • 图片位于HTML文件的image子文件夹中,CSS文件位于根文件夹中。您可以使用url("images/background.jpeg")

以下是包含上述建议的CSS:

body {
  font-family: cursive, serif;
  background: url("images/background.jpeg") no-repeat center center;
  background-attachment: fixed;
  background-size: cover;
}