CSS - scroll-padding-block-end 属性



CSS scroll-padding-block-end 指定块维度中元素的滚动填充结束边缘的偏移量。

可能的值

  • <length-percentage> - 有效的长度或百分比值,定义从滚动端口的相应边缘向内的偏移量。
  • <auto> - 从用户代理确定的滚动端口的相应边缘向内偏移。

适用于

所有滚动容器。

语法


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

CSS scroll-padding-block-end - 长度值

以下示例演示如何使用 scroll-padding-block-end 属性使用长度值 (30px) 设置 div 元素在块维度中的滚动填充结束边缘的偏移量。


<html>
<head>
<style>
	 	#container {
	 	 	 width: 50%;
	 	 	 aspect-ratio: 3/1;
	 	 	 padding: 40px 0;
	 	 	 border: solid black 2px;
	 	 	 overflow-x: hidden;
	 	 	 overflow-y: scroll;
	 	 	 scroll-snap-type: y mandatory;
	 	 	 scroll-padding-block-end: 30px;
	 	}

	 	.boxA {
	 	 	 background-color: rgb(234, 234, 128);
	 	 	 width: 85%;
	 	 	 aspect-ratio: 3/1;
	 	}

	 	.boxB {
	 	 	 background-color: lightgreen;
	 	 	 width: 70%;
	 	 	 aspect-ratio: 4/1;
	 	}

	 	.boxA, .boxB {
	 	 	 margin: 2px;
	 	 	 scroll-snap-align: start none;
	 	}
</style>
</head>
<body>
	 	<h3>CSS scroll-padding-block-end property.</h3>
	 	<p>scroll-padding-block-end property sets the offset for the end edge of the scrollport of an element in the block dimension.</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>

CSS scroll-padding-block-end - 百分比值

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


<html>
<head>
<style>
	 	#container {
	 	 	 width: 50%;
	 	 	 aspect-ratio: 3/1;
	 	 	 padding: 40px 0;
	 	 	 border: solid black 2px;
	 	 	 overflow-x: hidden;
	 	 	 overflow-y: scroll;
	 	 	 scroll-snap-type: y mandatory;
	 	 	 scroll-padding-block-end: 60%;
	 	}

	 	.boxA {
	 	 	 background-color: rgb(234, 234, 128);
	 	 	 width: 85%;
	 	 	 aspect-ratio: 3/1;
	 	}

	 	.boxB {
	 	 	 background-color: lightgreen;
	 	 	 width: 70%;
	 	 	 aspect-ratio: 4/1;
	 	}

	 	.boxA, .boxB {
	 	 	 margin: 2px;
	 	 	 scroll-snap-align: start none;
	 	}
</style>
</head>
<body>
	 	<h3>CSS scroll-padding-block-end property.</h3>
	 	<p>scroll-padding-block-end property sets the offset for the end edge of the scrollport of an element in the block dimension.</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>

CSS scroll-padding-block-end - 自动值

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


<html>
<head>
<style>
	 	#container {
	 	 	 width: 50%;
	 	 	 aspect-ratio: 3/1;
	 	 	 padding: 40px 0;
	 	 	 border: solid black 2px;
	 	 	 overflow-x: hidden;
	 	 	 overflow-y: scroll;
	 	 	 scroll-snap-type: y mandatory;
	 	 	 scroll-padding-block-end: auto;
	 	}

	 	.boxA {
	 	 	 background-color: rgb(234, 234, 128);
	 	 	 width: 85%;
	 	 	 aspect-ratio: 3/1;
	 	}

	 	.boxB {
	 	 	 background-color: lightgreen;
	 	 	 width: 70%;
	 	 	 aspect-ratio: 4/1;
	 	}

	 	.boxA, .boxB {
	 	 	 margin: 2px;
	 	 	 scroll-snap-align: start none;
	 	}
</style>
</head>
<body>
	 	<h3>CSS scroll-padding-block-end property.</h3>
	 	<p>scroll-padding-block-end property sets the offset for the end edge of the scrollport of an element in the block dimension.</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>