<!DOCTYPE html>
<html>
<head>
<style>
#container {
width: 40%;
aspect-ratio: 2/3;
margin: auto;
border: solid black 2px;
overflow-x: hidden;
overflow-y: scroll;
scroll-snap-type: y mandatory;
white-space: nowrap;
writing-mode: vertical-rl;
scroll-padding-inline-end: 20px;
}
.blue {
background-color: lightblue;
width: 95%;
aspect-ratio: 5/6;
}
.green {
background-color: lightgreen;
width: 80%;
aspect-ratio: 3/4;
}
.blue, .green {
display: inline-block;
margin: 2px;
scroll-snap-align: none end;
}
</style>
</head>
<body>
<h1>CSS scroll-padding-inline-end 属性</h1>
<p>当 writing-mode 属性值设置为 vertical-rl 时,元素在行内方向上的终点从右侧变为底部,这也会影响 scroll-padding-inline-end 属性。</p>
<p>在此例中,行内方向的吸附位置设置为终点位置,因此焦点元素应该吸附到距离容器右侧(在此模式下实为底部)20px 的位置。但由于 writing-mode 的值,焦点元素实际上在子元素与容器底部之间有一个 20px 的偏移距离。</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>
</body>
</html>