CSS - scroll-padding-left



CSS scroll-padding-left 屬性指定滾動容器的左邊緣和元素的滾動捕捉區域之間的空間量。

可能的值

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

應用於

所有 HTML 元素。

DOM 語法

object.style.scrollPaddingLeft = "length";

CSS 滾動填充左側 - 零值

以下示例演示如何使用scroll-padding-left: 0 屬性來確保容器底部沒有填充 -

<html>
<head>
<style>
   .scroll-container {
      width: 350px;
      height: 200px;
      overflow-x: hidden;
      overflow-y: scroll;
      scroll-snap-type: y mandatory;
      scroll-padding-left: 0;
   }
   .scrolling-section1,
   .scrolling-section2,
   .scrolling-section3 {
      width: 350px;
      height: 200px;
      scroll-snap-align: start;
   }
   .scrolling-section1 {
      background-color: rgb(220, 235, 153);
   }
   .scrolling-section2 {
      background-color: rgb(230, 173, 218);
   }
   .scrolling-section3 {
      background-color: rgb(119, 224, 210);
   }
</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-padding-left: 0</div>
      <div class="scrolling-section2">scroll-padding-left: 0</div>
      <div class="scrolling-section3">scroll-padding-left: 0</div>
   </div>
</body>
</html>

CSS 滾動填充左側 - 長度值

以下示例演示如何使用scroll-padding-left 屬性在可滾動容器的左側新增填充 -

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