CSS - scroll-margin-bottom



CSS scroll-margin-bottom 屬性用於控制滾動容器底部的外邊距。

可能的值

  • <length> − 長度值是一個數值,例如 px、em。

應用於

所有HTML元素。

DOM語法

object.style.scrollMarginBottom = "length";

CSS Scroll Margin Bottom - 零值

下面的例子演示瞭如何使用scroll-margin-bottom: 0移除滾動區域周圍的底部邊距:

<html>
<head>
<style>
   .scroll-container {
      width: 300px;
      height: 200px;
      overflow-x: hidden;
      overflow-y: scroll;
      scroll-snap-type: y mandatory;
   }
   .scrolling-section1,
   .scrolling-section2,
   .scrolling-section3 {
      width: 300px;
      height: 200px;
      scroll-snap-align: end;
   }
   .scrolling-section1 {
      background-color: rgb(220, 235, 153);
      scroll-margin-bottom: 0;
   }
   .scrolling-section2 {
      background-color: rgb(230, 173, 218);
      scroll-margin-bottom: 0;
   }
   .scrolling-section3 {
      background-color: rgb(119, 224, 210);
      scroll-margin-bottom: 0;
   }
</style>
</head>
<body>
   <h3>Scroll the content using the scrollbar arrows to see the effect.</h3>
   <div class="scroll-container">
      <div class="scrolling-section1">scroll-margin-bottom: 0</div>
      <div class="scrolling-section2">scroll-margin-bottom: 0</div>
      <div class="scrolling-section3">scroll-margin-bottom: 0</div>
   </div>
</body>
</html>

CSS Scroll Margin Bottom - 長度值

下面的例子演示瞭如何使用scroll-margin-bottom屬性為每個區域新增底部邊距,這會影響內容的滾動行為:

<html>
<head>
<style>
   .scroll-container {
      width: 300px;
      height: 200px;
      overflow-x: hidden;
      overflow-y: scroll;
      scroll-snap-type: y mandatory;
   }
   .scrolling-section1,
   .scrolling-section2,
   .scrolling-section3 {
      width: 300px;
      height: 200px;
      scroll-snap-align: end;
   }
   .scrolling-section1 {
      background-color: rgb(220, 235, 153);
      scroll-margin-bottom: 20px;
   }
   .scrolling-section2 {
      background-color: rgb(230, 173, 218);
      scroll-margin-bottom: 2em;
   }
   .scrolling-section3 {
      background-color: rgb(119, 224, 210);
      scroll-margin-bottom: 10px;
   }
</style>
</head>
<body>
   <h3>Scroll the content using the scrollbar arrows to see the effect.</h3>
   <div class="scroll-container">
      <div class="scrolling-section1">scroll-margin-bottom: 20px</div>
      <div class="scrolling-section2">scroll-margin-bottom: 2em</div>
      <div class="scrolling-section3">scroll-margin-bottom: 10px</div>
   </div>
</body>
</html>
廣告