<!DOCTYPE html>
<html>
<head>
<style>
#container {
width: 50%;
aspect-ratio: 1;
margin: auto;
border: solid black 2px;
overflow-x: scroll;
overflow-y: hidden;
scroll-snap-type: x mandatory;
writing-mode: vertical-rl;
scroll-padding-bottom: 30px;
}
#container > div {
margin: 2px;
scroll-snap-align: end none;
}
.green {
background-color: lightgreen;
height: 95%;
aspect-ratio: 2/3;
}
.blue {
background-color: lightblue;
height: 80%;
aspect-ratio: 1/2;
}
</style>
</head>
<body>
<h1>改变吸附位置后的 CSS scroll-padding-bottom 属性</h1>
<p>为了使 scroll-padding-bottom 生效,吸附位置必须设置在子元素的底部。在英文书写的页面中,通常可以通过将 scroll-snap-align 设置为 'end none' 来将吸附位置设置在子元素的底部,因为块级方向是向下的。但是,如果我们通过设置 writing-mode 属性值为 'vertical-rl' 来改变块级方向,吸附位置就会从子元素的底部变为左侧。在这种情况下,scroll-padding-bottom 属性将不再起作用。</p>
<div id="container">
<div class="blue">Blue</div>
<div class="green">Green</div>
<div class="blue">Blue</div>
<div class="green">Green</div>
<div class="blue">Blue</div>
<div class="green">Green</div>
<div class="blue">Blue</div>
<div class="green">Green</div>
</div>
</body>
</html>