scroll-padding
Set scroll padding to 20px from the container to the snap position:
div {
scroll-padding: 20px;
}
Try it Yourself »
Definition scroll-padding
Подработка: Перевод страницы
The scroll-padding
property specifies the distance from the container to the snap position of child elements.
This means that when you stop scrolling, the scrolling will quickly adjust and stop at a specified distance from the container to the snap position of the childelement in focus.
Snap position is the position on the child element where it snaps into place in the container when you stop scrolling.
Note: In the example above, scroll padding is set on all sides, but only the scroll padding on the top side changes the scrolling behaviour because the scroll-snap-align is set to "start".
The scroll-padding
property is a shorthand property for the following properties:
Values for the scroll-padding
property can be set in different ways:
If the scroll-padding property has four values:
- scroll-padding: 15px 30px 60px 90px;
- top distance is 15px
- right distance is 30px
- bottom distance is 60px
- left distance is 90px
If the scroll-padding property has three values:
- scroll-padding: 15px 30px 60px;
- top distance is 15px
- left and right distances are 30px
- bottom distance is 60px
If the scroll-padding property has two values:
- scroll-padding: 15px 30px;
- top and bottom distances are 15px
- left and right distances are 30px
If the scroll-padding property has one value:
- scroll-padding: 10px;
- all four distances are 10px
To see the effect from the scroll-padding
property, the scroll-snap-align
property must be set on the child elements, and the scroll-padding
and scroll-snap-type
properties must be set on the parent element.
Default value: | auto |
---|---|
Inherited: | no |
Animatable: | no. Read about animatable |
Version: | CSS3 |
JavaScript syntax: | object.style.scrollPadding="20px" Try it |
Browser Support scroll-padding
The numbers in the table specify the first browser version that fully supports the property.
Property | |||||
---|---|---|---|---|---|
scroll-padding | 69.0 | 79.0 | 68.0 | 14.1 | 56.0 |
CSS Syntax scroll-padding
scroll-padding: auto|value|initial|inherit;
Property Values scroll-padding
Value | Description |
---|---|
auto | Default value. The browser calculates the padding |
length | Specifies scroll-padding in px, pt, cm, etc. Negative values are not allowed. Read about length units |
% | Specifies the padding in percent of the width of the containing element |
initial | Sets this property to its default value. Read about initial |
inherit | Inherits this property from its parent element. Read about inherit |
More Examples scroll-padding
The scroll-padding
property can be used in an image gallery with snap behaviour, to push images below a fixed element:
#container {
scroll-padding: 30px 0 0 0;
}
The scroll-padding
property can be set at both the bottom and the right side of the container. Scroll to the next element both horizontally and vertically to see the effect:
#container {
scroll-padding: 0 10px 30px 0;
}
Related Pages scroll-padding
CSS scroll-padding-bottom property: CSS Scroll-padding-bottom property
CSS scroll-padding-left property: CSS Scroll-padding-left property
CSS scroll-padding-right property: CSS Scroll-padding-right property
CSS scroll-padding-top property: CSS Scroll-padding-top property
CSS scroll-snap-align property: CSS Scroll-snap-align property
CSS scroll-snap-type property: CSS Scroll-snap-type property