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