为什么滚动时背景会移动?

时间:2018-12-08 05:03:59

标签: css

每次滚动时,背景文本都会一直滚动到我滚动到的任何位置。如何使它保持在我想要的位置。

 .bg-image {
      background-image: url(../construction/3.jpg);
      filter: blur(8px);
      -webkit-filter: blur(8px);
      height: 100%;
      background-position: center;
      background-repeat: no-repeat;
      background-size: cover;
    }

.bg-text {
  background-color: #000; 
  background-color: #000; 
  color: white;
  font-weight: bold;
  border: 3px solid #f1f1f1;
  position: absolute;
  margin: auto;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 2;
  width: 80%;
  padding: 20px;
  text-align: center;
}

2 个答案:

答案 0 :(得分:0)

如果您固定了图像,则可以使用: .your-class{ background-image: url("your-image"); background-repeat: no-repeat; background-attachment: fixed; }`

答案 1 :(得分:0)

您应该固定背景图片,所以

 .bg-image {
      background-image: url(../construction/3.jpg);
      filter: blur(8px);
      -webkit-filter: blur(8px);
      height: 100%;
      background-position: center;
      background-repeat: no-repeat;
      background-size: cover;
      background-attachment: fixed;
    }

https://www.w3schools.com/cssref/tryit.asp?filename=trycss_background-attachment 我希望此链接会有所帮助。