CSS scroll-margin-bottom property
- Previous Page scroll-margin-block-start
- Next Page scroll-margin-inline
Definition and Usage
scroll-margin-bottom
The attribute specifies the distance between the吸附位置吸附位置 and the container.
吸附位置是指子元素在停止滚动时吸附到容器中的位置。
Snap position refers to the position in the container to which the child element snaps when scrolling stops. scroll-snap-align
Snap position is determined by property settings, but may also be affected by CSS properties
and writing-mode
influence.
Note:This property is only valid when the snap position is set at the bottom of the child element.
to see scroll-margin-bottom
properties on the parent element, and the scroll-margin-bottom
and scroll-snap-align
property, and set scroll-snap-type
property.
Instance
Example 1
Set the scroll margin bottom between the snap position and the container to 20px:
div { scroll-margin-bottom: 20px; }
Example 2: Image Library
scroll-margin-bottom
This property can be used in image galleries with snap behavior. In this example,scroll-margin-bottom
Let the user know that there is another image at the bottom. Scroll past the first image to see the effect:
#container > img { scroll-margin-bottom: 30px; }
Example 3: Snap Position
To make scroll-margin-bottom
property takes effect, and the snap position must be set at the bottom of the child element. In this example,writing-mode
When using this code, thescroll-margin-bottom
The following properties will no longer be valid:
#container { writing-mode: vertical-rl; } #container > div { scroll-margin-bottom: 30px; scroll-snap-align: end none; }
CSS Syntax
scroll-margin-bottom: 0;value|initial|inherit;
Property Value
Value | Description |
---|---|
0 | The bottom scroll margin is zero. This is the default value. |
length |
Specify the scroll margin bottom in units such as px, pt, cm, etc. Negative values are allowed. See:CSS Units. |
initial | Sets this property to its default value. See: initial. |
inherit | Inherits this property from its parent element. See: inherit. |
Technical Details
Default Value: | none |
---|---|
Inheritance: | No |
Animation Creation: | Not supported. See:Animation-related properties. |
Version: | CSS3 |
JavaScript Syntax: | object.style.scrollMarginBottom="20px" |
Browser Support
The numbers in the table represent the browser version that first fully supports this property.
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
69.0 | 79.0 | 68.0 | 14.1 | 56.0 |
Related Pages
Reference:CSS direction attribute
Reference:CSS scroll-snap-align property
Reference:CSS scroll-snap-type property
Reference:CSS writing-mode attribute
- Previous Page scroll-margin-block-start
- Next Page scroll-margin-inline