添加一些样式后,背景图像消失

时间:2017-12-31 19:02:49

标签: html css

如果我的问题很愚蠢,请原谅我,我对所有这些技术都很陌生。我的目标是在它没有缩放的情况下添加默认大小的图像背景,因为它是一个大尺寸的图片,问题是当我添加一些样式时,图像没有显示,背景变得空白。 顺便说一句,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;
}

1 个答案:

答案 0 :(得分:1)

你没有在background属性后添加分号:

#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 */
}