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;
}
.blue {
  background-color: lightblue;
  height: 95%;
  aspect-ratio: 6/5;
}
.green {
  background-color: lightgreen;
  height: 80%;
  aspect-ratio: 4/5;
}
.blue, .green {
  margin: 2px;
  display: inline-block;
  scroll-snap-align: none end;
  scroll-margin-block: 20px 0;
  writing-mode: vertical-rl;
}
</style>
</head>
<body>
<h1>CSS scroll-margin-block 属性</h1>
<p>当 writing-mode 属性值设置为 vertical-rl 时,元素在块方向上的起始位置从顶部变为右侧,这也会影响 scroll-margin-block 属性。</p>
<p>在此例中,吸附位置设置为在块方向上开始,因此焦点元素应该吸附到距离容器顶部 20 像素的位置。但由于 writing-mode 的值,焦点元素在子元素与容器右侧之间产生了 20 像素的外边距偏移。</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>