CSS 属性

CSS scroll-padding-inline-end 指定内联维度中滚动端口结束边缘的偏移量。

属性值

  • <length-percentage>: 有效的长度或百分比值,定义距滚动端口相应边缘的向内偏移。

  • <auto>: 距相应边缘的向内偏移由用户代理确定的滚动端口。

适用范围

所有滚动容器。

语法

scroll-padding-inline-end = auto | <length-percentage> 

CSSscroll-padding-inline-end: length 

下面的示例演示了如何使用scroll-padding-inline-end属性来设置scrollport结束边缘的偏移量内联尺寸,使用长度值(20px)。

<html>
<head>
<style>
   #container {
      width: 50%;
      height: 400px;
      aspect-ratio: 3/2;
      padding: 0 30px;
      border: solid black 2px;
      overflow-x: scroll;
      overflow-y: hidden;
      white-space: nowrap;
      scroll-snap-type: x mandatory;
      scroll-padding-inline-end: 2em;
   }

   .boxA {
      background-color: rgb(234, 234, 128);
      height: 75%;
      aspect-ratio: 5/3;
   }

   .boxB {
      background-color: lightblue;
      height: 60%;
      aspect-ratio: 5/4;
   }

   .boxA, .boxB {
      display: inline-block;
      margin: 2px;
      scroll-snap-align: none end;
   }
</style>
</head>
<body>
   <h3>CSS scroll-padding-inline-end 属性.</h3>
   <p>scroll-padding-inline-end 属性设置内联维度中元素结束边缘的滚动填充。</p>

   <div id="container">
      <div class="boxA"></div>
      <div class="boxB"></div>
      <div class="boxA"></div>
      <div class="boxB"></div>
      <div class="boxA"></div>
    </div>
</body>
</html> 

CSSscroll-padding-inline-end: 百分比

以下示例演示如何使用scroll-padding- inline-end 属性设置内联维度中 div 元素结束边缘的滚动填充,使用百分比值 (60%)。

<html>
<head>
<style>
   #container {
      width: 50%;
      height: 400px;
      aspect-ratio: 3/2;
      padding: 0 30px;
      border: solid black 2px;
      overflow-x: scroll;
      overflow-y: hidden;
      white-space: nowrap;
      scroll-snap-type: x mandatory;
      scroll-padding-inline-end: 60%;
   }

   .boxA {
      background-color: rgb(234, 234, 128);
      height: 75%;
      aspect-ratio: 5/3;
   }

   .boxB {
      background-color: lightblue;
      height: 60%;
      aspect-ratio: 5/4;
   }

   .boxA, .boxB {
      display: inline-block;
      margin: 2px;
      scroll-snap-align: none end;
   }
</style>
</head>
<body>
   <h3>CSS scroll-padding-inline-end 属性.</h3>
   <p>scroll-padding-inline-start 属性设置内联维度中元素结束边缘的滚动填充。</p>

   <div id="container">
      <div class="boxA"></div>
      <div class="boxB"></div>
      <div class="boxA"></div>
      <div class="boxB"></div>
      <div class="boxA"></div>
   </div>
</body>
</html> 

CSSscroll-padding-inline-end: auto 

以下示例演示如何使用scroll-padding-inline-end属性设置内联维度中div元素结束边缘的滚动填充,使用关键字值(auto)。

 <html>
<head>
<style>
   #container {
      width: 50%;
      height: 400px;
      aspect-ratio: 3/2;
      padding: 0 30px;
      border: solid black 2px;
      overflow-x: scroll;
      overflow-y: hidden;
      white-space: nowrap;
      scroll-snap-type: x mandatory;
      scroll-padding-inline-end: auto;
   }

   .boxA {
      background-color: rgb(234, 234, 128);
      height: 75%;
      aspect-ratio: 5/3;
   }

   .boxB {
      background-color: lightblue;
      height: 60%;
      aspect-ratio: 5/4;
   }

   .boxA, .boxB {
      display: inline-block;
      margin: 2px;
      scroll-snap-align: none end;
   }
</style>
</head>
<body>
   <h3>CSS scroll-padding-inline-end 属性.</h3>
   <p>scroll-padding-inline-end 属性设置内联维度中元素结束边缘的滚动填充。</p>

   <div id="container">
      <div class="boxA"></div>
      <div class="boxB"></div>
      <div class="boxA"></div>
      <div class="boxB"></div>
      <div class="boxA"></div>
   </div>
</body>
</html>