With snap scroll margin, I can position the snap before the default, which is useful when you want to avoid a fixed element, such as a navigation bar, obscuring the target element. However, in this case, I want the opposite. I want the snap position slightly after the start of the target element, in this case, a full-screen image, to hide the narrow wavy border at the top.
I have an absolute positioned svg wavy border at the top and bottom of the image. I have tried to use negative values with snap margin but no luck. Scroll-margin-top doesn't seem to accept negative margins. Lowering the default snap position with absolute positioning by creating a pseudo-element :after/:before also didn't work. Obviously, I don't know what I am doing. Any ideas?
Attempt 1:
.snap {
scroll-snap-align: start;
scroll-snap-stop: always;
scroll-margin-top: -20px;
}
Attempt 2:
.snap:after {
content: '';
top: 20px;
display: block;
position: absolute;
pointer-events: none;
scroll-snap-align: start;
scroll-snap-stop: always;
}
Simplified Html:
<figure class="position-relative">
<div class="top-divider">
<svg><use xlink:href="#divider-inf"></use></svg>
</div>
<img src="assets/img/hug/hug-3x2-lg.jpg" width="1200" height="800" alt="group hug" class="snap">
<figcaption>Peace, Love and Samb</figcaption>
<div class="bottom-divider">
<svg><use xlink:href="#divider-inf"></use></svg>
</div>
</figure>