Share:

How to 'href' to the element even to the top margin of each div?

The following is html code I have written to store some of my favorite gradients and I wanted to link anchor to 'id="grad1"' and 'id="grad2"' even including the margin at the top.

I thought the ':target:before' would work to provide the margin when those 'id's were targeted but that does not work for me somehow.

When I link to the below html, it only links to the top of the content, not to the top of the margin of each div.

we should add scroll-margin-top to each of your grads that is equal to the margin you apply.

Example:
#grad1 {
  margin-top: 200px;
  scroll-margin-top: 200px;
}
This way, anchors will scroll to the offset specified by the scroll-margin-top instead of the element border.

Comments

Popular posts from this blog

Get Color From Pixel C# WPF | Saatody | Amit Padhiyar

Basic Audio Operations With MP3 And Wave Files Using NAudio C#

Create Drag And Drop Operation Between DevExpress GridControl And Custom WPF UI | Saatody | Amit Padhiyar