x
 
<!DOCTYPE html>
<html>
<head>
<style>
#container {
  width: 80%;
  aspect-ratio: 2/1;
  margin: auto;
  border: solid black 2px;
  overflow-x: scroll;
  overflow-y: hidden;
  white-space: nowrap;
  scroll-snap-type: x mandatory;
  scroll-padding-left: 20px;
}
.blue {
  background-color: lightblue;
  height: 95%;
  aspect-ratio: 3/2;
}
.green {
  background-color: lightgreen;
  height: 80%;
  aspect-ratio: 4/3;
}
.blue, .green {
  display: inline-block;
  margin: 2px;
  scroll-snap-align: start;
}
</style>
</head>
<body>
<h1>CSS scroll-padding-left 属性</h1>
<p>在容器上设置了 scroll-padding-left 属性,以便子元素的吸附位置相对于容器左侧有一个偏移距离。</p>
<p>在此情况下,x 方向的吸附位置设置为开始位置,因此焦点元素应该吸附到容器的最左侧。但由于 scroll-padding-left 的值,焦点元素与容器左侧之间有一个 20px 的偏移距离。</p>
<div id="container">
  <div class="blue"></div>
  <div class="green"></div>
  <div class="blue"></div>
  <div class="green"></div>
  <div class="blue"></div>
  <div class="green"></div>
  <div class="blue"></div>
</div>
</body>
</html>