我想用拉伸(stretch)的图像文件覆盖整个 body 区域(任意 body )。我试过使用背景,但即使使用 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>
最佳答案
使用这个 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;
}
关于javascript - 如何用纯色图像覆盖整个网页(在顶部),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56194298/