CSS scroll-margin Property
Example
.scroller {
text-align: left;
width: 250px;
height: 250px;
overflow-x: scroll;
display: flex;
box-sizing: border-box;
border: 1px solid #000;
scroll-snap-type: x mandatory;
}
.scroller > div {
flex: 0 0 250px;
width: 250px;
background-color: #1A73E8;
color: #fff;
font-size: 30px;
display: flex;
align-items: center;
justify-content: center;
scroll-snap-align: start;
}
.scroller > div:nth-child(2n) {
background-color: #fff;
color: #1A73E8;
}
.scroller > div:nth-child(2) {
scroll-margin: 1rem;
}
.scroller > div:nth-child(3) {
scroll-margin: 2rem;
}
1
2
3
Meaning:
The scroll-margin CSS property sets all of the scroll margins of an element at once, assigning values much like the margin property does for margins of an element.
The scroll-margin property is a shorthand for the following CSS properties:
Default value: | 0 |
Inherited: | No |
Animatable: | No |
Version: | CSS3 |
JavaScript syntax: |
|
Standard Syntax
scroll-margin: length|initial|inherit|revert|revert-layer|unset;
Browser Support
Status
Property Values
The following table describes the values of this property:
Value | Description |
---|---|
length | An outset from the corresponding edge of the scroll container. |
initial | Sets this property to its default value. |
inherit | If specified, the associated element takes the computed value of its parent element animation-delay property. |
revert | Reverts the cascaded value of the property from its current value to the value the property |
revert-layer | Rollback styles to the ones specified in previous cascade layers. |
unset | Resets a property to its inherited value if the property naturally inherits from its parent, and to its initial value if not. |
Default CSS Property Values
selectors {
scroll-margin: 0;
}