CSS - scroll-margin-block-start



The property scroll-margin-block-start allows you to control the margin at the start of the block axis (usually the top in LTR languages) of the snapport.

This area is computed by taking the border box that has been modified, finding its rectangular bounding box inside the coordinate system of the scroll container, and then adding the specified outsets.

Possible Value

<length> - An offset from the block start edge of the scroll container.

Applies to

All elements

Syntax

scroll-margin-block-start = <length>     

CSS scroll-margin-block-start - Basic Example

The following example demonstrates the usage of scroll-margin-block-start property.

<html>
<head>
<style>
   #demoScroll {
      width: 90%;
      aspect-ratio: 16/9;
      padding: 20px;
      margin: auto;
      border: solid 3px #333;
      overflow-x: hidden;
      overflow-y: scroll;
      scroll-snap-type: y mandatory;
   }
   .snap-block {
      width: 90%;
      aspect-ratio: 16/9;
      scroll-snap-align: start none;
      scroll-margin-block-start: 50px; 
      border-radius: 20px;
   }
   .blue { background-color: #3498db; }
   .green { background-color: #27ae60; }
   .yellow { background-color: #f39c12; }
   .red { background-color: #e74c3c; }
   .purple { background-color: #9b59b6; }
</style>
</head>
<body>
<h3>scroll-margin-block-start</h3>
<p>Scroll through the colorful blocks.</p>
<div id="demoScroll">
   <div class="snap-block blue"></div>
   <div class="snap-block green"></div>
   <div class="snap-block yellow"></div>
   <div class="snap-block red"></div>
   <div class="snap-block purple"></div>
</div>
</body>
</html>
Advertisements