java如何使用css在html部分添加背景图像?
我试图在我的分区标签中添加背景图像,但它不起作用。 我已经采取了正确的文件,但它仍然没有显示在网页上,完全相同的代码,我看到有人写在他的代码在youtube上,这是有效的
*
{
padding: 0;
margin: 0;
}
.header
{
height: 100%;
background-image: linear-gradient(rgba(0,0,0,0.6),rgba(0,0,0,0.6)),url(images/taj-mahal.jpg);
background-repeat: no-repeat;
background-size: cover;
background-position: center;
background-attachment: fixed;
}
<!DOCTYPE html>
<html>
<head>
<title>Visit India</title>
<link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
</head>
<body>
<section class="header">
<div class="container">
</div>
</section>
</body>
</html>
# 1 楼答案
将图像的路径用引号括起来
# 2 楼答案
您需要在图像路径周围添加单引号
# 3 楼答案
当您有一些容器的内容时,将加载背景图像。现在“.header”部分的高度为零。 或者您可以将height:100%更改为height:100vh以检查显示的背景图像