CSS - scroll-padding-right 属性



CSS scroll-padding-right 属性指定滚动容器的右边缘与元素的滚动捕捉区域之间的空间量。

可能的值

  • <length> : 长度值是一个数值,例如 px、em、percentage。

适用于

所有 HTML 元素。

DOM 语法


object.style.scrollPaddingRight = "length";

CSS scroll-padding-right - 零值

以下示例演示了如何使用 scroll-padding-right: 0 属性来确保容器底部没有填充 -


<html>
<head>
<style>
	 	.scroll-container {
	 	 	 display: flex;
	 	 	 width: 350px;
	 	 	 height: 200px;
	 	 	 overflow-x: scroll;
	 	 	 overflow-y: hidden;
	 	 	 scroll-snap-type: x mandatory;
	 	 	 scroll-padding-right: 0;
	 	}
	 	.scrolling-section1,
	 	.scrolling-section2,
	 	.scrolling-section3 {
	 	 	 flex: 0 0 auto;
	 	 	 width: 350px;
	 	 	 height: 200px;
	 	 	 scroll-snap-align: end;
	 	}
	 	.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-right: 0</div>
	 	 	 <div class="scrolling-section2">scroll-padding-right: 0</div>
	 	 	 <div class="scrolling-section3">scroll-padding-right: 0</div>
	 	</div>
</body>
</html>

CSS scroll-padding-right - 长度值

以下示例演示了如何使用 scroll-padding-right 属性在可滚动容器的右侧添加填充 -


<html>
<head>
<style>
	 	.scroll-container {
	 	 	 display: flex;
	 	 	 width: 350px;
	 	 	 height: 200px;
	 	 	 overflow-x: scroll;
	 	 	 overflow-y: hidden;
	 	 	 scroll-snap-type: x mandatory;
	 	 	 scroll-padding-right: 25px;
	 	}
	 	.scrolling-section1,
	 	.scrolling-section2,
	 	.scrolling-section3 {
	 	 	 flex: 0 0 auto;
	 	 	 width: 350px;
	 	 	 height: 200px;
	 	 	 scroll-snap-align: end;
	 	}
	 	.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-right: 25px</div>
	 	 	 <div class="scrolling-section2">scroll-padding-right: 25px</div>
	 	 	 <div class="scrolling-section3">scroll-padding-right: 25px</div>
	 	</div>
</body>
</html>