scroll-margin-block-end

Baseline 已廣泛支援

此功能已成熟,並可在多種裝置和瀏覽器版本上執行。自 2021 年 9 月起,所有瀏覽器均已支援此功能。

scroll-margin-block-end 屬性定義了用於將此框對齊到吸附埠的塊維度末尾的滾動吸附區域的邊距。滾動吸附區域是透過獲取轉換後的邊框,找到其矩形邊界框(在滾動容器的座標空間中軸對齊),然後新增指定的外部偏移量來確定的。

試一試

scroll-margin-block-end: 0;
scroll-margin-block-end: 20px;
scroll-margin-block-end: 2em;
<section class="default-example" id="default-example">
  <div class="scroller">
    <div>1</div>
    <div id="example-element">2</div>
    <div>3</div>
  </div>
  <div class="info">Scroll »</div>
</section>
.default-example .info {
  inline-size: 100%;
  padding: 0.5em 0;
  font-size: 90%;
  writing-mode: vertical-rl;
}

.scroller {
  text-align: left;
  height: 250px;
  width: 270px;
  overflow-y: scroll;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  border: 1px solid black;
  scroll-snap-type: y mandatory;
}

.scroller > div {
  flex: 0 0 250px;
  background-color: rebeccapurple;
  color: white;
  font-size: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  scroll-snap-align: end;
}

.scroller > div:nth-child(even) {
  background-color: white;
  color: rebeccapurple;
}

語法

css
/* <length> values */
scroll-margin-block-end: 10px;
scroll-margin-block-end: 1em;

/* Global values */
scroll-margin-block-end: inherit;
scroll-margin-block-end: initial;
scroll-margin-block-end: revert;
scroll-margin-block-end: revert-layer;
scroll-margin-block-end: unset;

<length>

從滾動容器的塊末端邊緣向外的偏移量。

正式定義

初始值0
應用於所有元素
繼承性
計算值同指定值
動畫型別按計算值型別

正式語法

scroll-margin-block-end = 
<length>

規範

規範
CSS 滾動捕捉模組級別 1
# margin-longhands-logical

瀏覽器相容性

另見