我有一个简单的代码,在 html 的 body 标签内有一个文本,一个 css 样式表只是为了有一个背景图像,我不确定为什么背景图像根本不显示。
这是我的 html:
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
<link rel="stylesheet" type="text/css" href="styles.css">
</head>
<body>
Test
</body>
</html>
CSS 就是这样的:
#body {
background-image: url(images/ninja.jpg);
}
我在图像文件夹中有 "ninja.jpg"
。并且仍然没有显示背景图像。我也尝试过将 images/ninja.jpg
放在引号内(即:"images/ninja.jpg"
),但它不起作用。
最佳答案
不要使用#body
使用body
尝试
body { background-image: url(images/ninja.jpg); }
用于 CSS
#body指的是属性为id="body"
body {background-color: green;} /*this is the actual body*/
#body{background-color: red;} /*this is the paragraph*/
This is green
<p id="body">This is red</p>
关于html - 为什么 body 背景图像不显示?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38369960/