CSS scroll-margin-bottom 屬性
更多“自己嘗試”的例子見下文。
定義和用法
scroll-margin-bottom
屬性指定吸附位置和容器之間的距離。
對齊點是當您停止滾動時,子元素吸附到容器中的位置。對齊點使用 scroll-snap-align
屬性設定,但也會受到 CSS 屬性 direction
和 writing-mode
的影響。
注意: 此屬性僅在吸附位置位於子元素底部時生效。
要看到 scroll-margin-bottom
屬性的效果,子元素必須設定 scroll-margin-bottom
和 scroll-snap-align
屬性,父元素必須設定 scroll-snap-type
屬性。
瀏覽器支援
表中的數字指定了完全支援該屬性的第一個瀏覽器版本。
屬性 | |||||
---|---|---|---|---|---|
scroll-margin-bottom | 69.0 | 79.0 | 68.0 | 14.1 | 56.0 |
CSS 語法
scroll-margin-bottom: 0|值|initial|inherit;
屬性值
值 | 描述 |
---|---|
0 | Scroll-margin-bottom 為零。這是預設值 |
length | 指定 scroll-margin-bottom 的畫素、磅、釐米等。允許負值。 瞭解長度單位 |
initial | 將此屬性設定為其預設值。閱讀關於initial |
inherit | 從其父元素繼承此屬性。閱讀關於inherit |
更多示例
圖片庫
scroll-margin-bottom
屬性可以在具有吸附行為的圖片庫中使用。在這裡,scroll-margin-bottom 讓使用者知道底部有一張圖片。滾動過第一張圖片即可看到效果
#container > img {
scroll-margin-bottom: 30px;
}





吸附點
為了使 scroll-margin-bottom
屬性生效,吸附位置必須位於子元素的底部。在此示例中,writing-mode
屬性將吸附位置從子元素的底部更改為左側。使用如下程式碼時,scroll-margin-bottom
屬性將不再起作用
#container {
writing-mode: vertical-rl;
}
#container > div {
scroll-margin-bottom: 30px;
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 屬性