<!DOCTYPE html>
<html>
<head>
<style>
#container {
position: relative;
width: 60%;
aspect-ratio: 2/3;
margin: auto;
border: solid black 2px;
}
#topDiv {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 25px;
z-index: 1;
background-color: rgba(0, 0, 0, 0.8);
color: white;
}
#imgDiv {
position: absolute;
inset: 0 0 0 0;
padding-top: 40px;
overflow-x: hidden;
overflow-y: scroll;
scroll-snap-type: y mandatory;
scroll-padding-block-start: 30px;
}
#imgDiv > img {
width: 95%;
margin: 2px;
scroll-snap-align: start none;
}
</style>
</head>
<body>
<h1>CSS scroll-padding-block-start 属性</h1>
<p>在图片库框内垂直拖动滚动条,然后松开,观察在块方向设置为开始吸附位置,且容器设置了 30px 的 scroll-padding-block-start 时的滚动吸附效果。scroll-padding-block-start 属性值的作用是使图片相对于固定的顶部元素向下偏移。</p>
<div id="container">
<div id="topDiv">Fixed top element</div>
<div id="imgDiv">
<img src="/i/photo/beijing.jpg" alt="Beijing" width="600" height="400">
<img src="/i/photo/dancer.png" alt="Dancer" width="500" height="749">
<img src="/i/photo/wuhan.jpg" alt="Wuhan" width="600" height="400">
<img src="/i/photo/tulip.jpg" alt="Tulip" width="300" height="300">
<img src="/i/photo/hangzhou.jpg" alt="Hangzhou" width="600" height="400">
</div>
</div>
</body>
</html>