有些官网可能会存在这一的展示
实现思路:
background-attachment: fixed;
内容参考:background-attachment - CSS:层叠样式表 | MDN
代码如下:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
div {
width: 400px;
height: 200px;
overflow: auto;
}
.word {
width: 100%;
height: 100%;
font-size: 100px;
color: white;
text-align: center;
}
.word:nth-child(odd) {
background: rgb(83, 121, 84);
}
.img {
width: 400px;
height: 200px;
background-image: var(--i);
background-size: 400px 200px;
background-position: center center;
background-attachment: fixed;
font-size: 100px;
color: wheat;
text-align: center;
}
</style>
</head>
<body>
<div class="box">
<div class="word">1</div>
<div class="img" style="--i: url(./imgs/1.jpg)"></div>
<div class="word">2</div>
<div class="img" style="--i: url(./imgs/2.jpg)"></div>
<div class="word">3</div>
<div class="img" style="--i: url(./imgs/3.jpg)"></div>
<div class="word">4</div>
<div class="img" style="--i: url(./imgs/4.jpg)"></div>
</div>
</body>
</html>