Open In App

CSS scroll-margin-block-end property

Last Updated : 29 Aug, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

The scroll-margin-block-end property is used to set all the scroll margins to the end side of a scroll element at once. This property defines the margin of the scroll snap area at the end of the block dimension that is used for snapping this box to the snap port. 

Syntax:

scroll-margin-block-end: length

/* Or */

scroll-margin-block-end: Global_Values

Property values: This property accepts two properties mentioned above and described below:

  • length: This property refers to the values defined with length units like em, px, rem, vh, etc.
  • Global_Values: This property refers to the global values like inherit, initial, unset, etc.

Note: scroll-margin-block-end doesn’t accept percentage value as the length.

Example: In this example, you can see the effect of scroll-margin-block-end by scrolling to a point partway between two of the “interfaces” of the example’s content.

HTML




<!DOCTYPE html>
<html>
<head>
    <style>
        .interfaces {
              width:278px;
              height:296px;
              scroll-snap-align: end none;
              display: flex;
              align-items: center;
              justify-content: center;
              font-size: 60px;
              color: white;
        }
        .doc {
              width: 300px;
              height:300px;
              overflow-x: hidden;
              overflow-y: auto;
              white-space: nowrap;
              scroll-snap-type:y mandatory;
        }
    </style>
</head>
<body>
    <div class="doc">
        <div class="interfaces" style=
              "background-color: rgb(178, 248, 16);
              scroll-margin-block-end: 90px;">
              Geek 1
        </div>
        <div class="interfaces" style=
              "color: black;
              scroll-margin-block-end: 90px;">
              Geek 2
        </div>
        <div class="interfaces" style=
              "background-color: green;
              scroll-margin-block-end: 90px;">
              Geek 3
        </div>
        <div class="interfaces" style=
              "color: green;
              scroll-margin-block-end: 90px;">
              Geek 4
        </div>
        <div class="interfaces" style=
              "background-color: rgb(34, 177, 34);
              scroll-margin-block-end: 90px;">
              Geek 5
        </div>
        <div class="interfaces" style=
              "background-color: rgb(108, 216, 162);
              scroll-margin-block-end: 90px;">
              Geek 6
        </div>
    </div>
</body>
</html>


Output: This example shows a snapping area of 90px on scrolling.

Supported Browsers:

  • Google Chrome 69
  • Edge 79
  • Firefox 68
  • Opera 56
  • Safari 14.1


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads