如果我的问题很愚蠢,请原谅我,我对所有这些技术都很陌生。我的目标是在默认大小下添加图像背景,同时由于它是大尺寸图片而不会缩放,问题是当我添加一些样式时,图像不显示并且背景变空白。 顺便说一下,IM 在这个背景图片上使用了 particle.js。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Infinite Space !</title>
<link rel="stylesheet" href="style.css">
</head>
<body >
<div id="particles-js"></div>
//particle-js configues
<script src="https://cdn.jsdelivr.net/npm/particles.js@2.0.0/particles.min.js">
</script>
<script>
particlesJS.load('particles-js', 'particles.json', function() {
console.log('callback - particles.js config loaded');
});
</script>
</div>
</body>
</html>
#particles-js{
background: url("https://d14xs1qewsqjcd.cloudfront.net/assets/bg-header-star.jpg")
width: 100%;
min-height: 800px;
background-size: contain;
background-repeat: no-repeat;
background-position: center;
/* background-attachment: fixed;
}
最佳答案
您没有在背景属性后添加分号:
#particles-js{
background: url("https://d14xs1qewsqjcd.cloudfront.net/assets/bg-header-star.jpg") /* <---- Semicolon goes here*/
width: 100%;
min-height: 800px;
background-size: contain;
background-repeat: no-repeat;
background-position: center;
/* background-attachment: fixed; /* Also you didnt close this comment */
}
关于html - 添加一些样式后背景图像消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48045067/