如何用实体图像覆盖整个网页正文(顶部)

时间:2019-05-17 22:30:30

标签: javascript css dom

我想用拉伸后的图像文件覆盖整个身体区域(任意身体)。我尝试使用背景,但即使使用z-index也不是这样。

我在下面尝试过,但这只是将真实的网页向下推。

<!DOCTYPE html>
        <html>
          <head>
            <meta charset="utf-8" />
            <title></title>
            <style>
              .box {
                width: 100%;
                height: 100%;
                z-index: 999;
                background-size: 1%;
                background-repeat: repeat;
              }
            </style>
          </head>
          <body>
            <div>
              <img src="solid-white.png" class="box" />
              <div>ajldfskaf</div>
            </div>
          </body>
        </html>

2 个答案:

答案 0 :(得分:1)

使用此CSS(无需其他元素):

body { position: relative; }
body::before {
  content: "";
  background-image: url(path/to/your/solid-white.png);
  background-size: cover;
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 9999;
}

答案 1 :(得分:0)

尝试一下:

<title/>