make anchor link ignore header code example

Example 1: How to prevent anchor links from scrolling behind a sticky header with one line of CSS

// src/scss/navigation.scss

$sticky-breakpoint: 32em;

// 1. Approximate height of sticky navigation.
[id] {
  @media (min-height: $sticky-breakpoint) {
    scroll-margin-top: 100px; // 1
  }
}

.navigation {
  // ...

  @media (min-height: $sticky-breakpoint) {
    position: sticky;
    top: 0;
  }
}

Example 2: offset anchor tag when scrolling

a.anchor {
    display: block;
    position: relative;
    top: -250px;
    visibility: hidden;
}

Tags:

Css Example