CSS scroll-padding-bottom 屬性
更多“自己嘗試”的例子見下文。
定義和用法
scroll-padding-bottom
屬性指定容器底部到子元素對齊位置的距離。
對齊點是當您停止滾動時,子元素吸附到容器中的位置。對齊點使用 scroll-snap-align
屬性設定,但也會受到 CSS 屬性 direction
和 writing-mode
的影響。
注意: 此屬性僅在對齊位置位於子元素底部時才生效。
要看到 scroll-padding-bottom
屬性的效果,必須在子元素上設定 scroll-snap-align
屬性,並在父元素上設定 scroll-padding-bottom
和 scroll-snap-type
屬性。
瀏覽器支援
表中的數字指定了完全支援該屬性的第一個瀏覽器版本。
屬性 | |||||
---|---|---|---|---|---|
scroll-padding-bottom | 69.0 | 79.0 | 68.0 | 14.1 | 56.0 |
CSS 語法
scroll-padding-bottom: auto|值|initial|inherit;
屬性值
值 | 描述 |
---|---|
auto | 預設值。瀏覽器會自動計算內邊距。 |
length | 以 px, pt, cm 等單位指定 scroll-padding-bottom。不允許負值。 閱讀長度單位 |
% | 指定相對於包含塊元素寬度的百分比內邊距。 |
initial | 將此屬性設定為其預設值。閱讀關於initial |
inherit | 從其父元素繼承此屬性。閱讀關於inherit |
更多示例
圖片庫
scroll-padding-bottom
屬性可用於帶有吸附行為的圖片庫,將圖片推到固定元素上方
#container {
scroll-padding-bottom: 30px;
}





設定底部滾動內邊距
當在兩個方向上都設定了吸附行為時,scroll-padding-bottom
屬性也可以應用於容器。垂直滾動到下一個元素即可看到效果。
#container {
scroll-padding-bottom: 30px;
}
吸附點
要使 scroll-padding-bottom
屬性生效,吸附位置必須位於子元素的底部。在此示例中,writing-mode
屬性將吸附位置從子元素的底部更改為左側。使用類似的程式碼將不再使 scroll-padding-bottom
屬性生效。
#container {
writing-mode: vertical-rl;
scroll-padding-bottom: 30px;
}
#container > div {
scroll-snap-align: end none;
}
自己動手試一試 »
相關頁面
CSS direction 屬性:CSS Direction 屬性
CSS scroll-snap-align 屬性:CSS Scroll-snap-align 屬性
CSS scroll-snap-type 屬性:CSS Scroll-snap-type 屬性
CSS writing-mode 屬性:CSS Writing-mode 屬性