CSS - scroll-padding-block-start
CSS scroll-padding-block-start specifies the offsets for the start edge of the scroll padding of an element in the block dimension.
Possible Values
-
<length-percentage> − A valid length or percentage value, defining an inwards offset from the corresponding edge of the scrollport.
<auto> − An inwards offset from the corresponding edge of the scrollport determined by the user agent.
Applies to
All the scroll containers.
Syntax
scroll-padding-block-start = auto | <length-percentage>
CSS scroll-padding-block-start - length Value
The following example demonstrates how to use the scroll-padding-block-start property to set the offset for the start edge of the scroll padding of the div element in the block dimension, using a length value (30px).
<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-start: 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-start property.</h3>
<p>scroll-padding-block-start property sets the offset for the start 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-start - percentage Value
The following example demonstrates how to use the scroll-padding-block-start property to set the offset for the start edge of the scroll padding of the div element in the block dimension, using a percentage value (60%).
<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-start: 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-start property.</h3>
<p>scroll-padding-block-start property sets the offset for the start 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-start - auto Value
The following example demonstrates how to use the scroll-padding-block-start property to set the offset for the start edge of the scroll padding of the div element in the block dimension, using a keyword value (auto).
<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-start: 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-start property.</h3>
<p>scroll-padding-block-start property sets the offset for the start 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>