<!DOCTYPE html>
<html>
<head>
<style>
#container {
position: relative;
width: 60%;
aspect-ratio: 3/2;
margin: auto;
border: solid black 2px;
}
#leftDiv {
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 25px;
z-index: 1;
background-color: rgba(0, 0, 0, 0.8);
color: white;
writing-mode: vertical-lr;
text-orientation: upright;
}
#imgDiv {
position: absolute;
inset: 0 0 0 0;
padding-left: 40px;
overflow-x: scroll;
overflow-y: hidden;
scroll-snap-type: x mandatory;
white-space: nowrap;
scroll-padding-inline-start: 30px;
}
#imgDiv > img {
height: 95%;
margin: 2px;
scroll-snap-align: none start;
}
</style>
</head>
<body>
<h1>CSS scroll-padding-inline-start 属性</h1>
<p>在图片库框内滚动,停止滚动后,观察子元素在行内方向设置为开始吸附位置,且容器设置了 30px 的 scroll-padding-inline-start 时的滚动吸附效果。scroll-padding-inline-start 属性值的作用是使图片从左侧固定元素的后面偏移出来。</p>
<div id="container">
<div id="leftDiv">Fixed</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>