Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to offset a anchor link to clear fixed header?

As the title describes. I am trying to offset the anchor link, so it appears 100px from the top of the viewport.

This is what I have tried so far.

<style>
   :target {
      display: block;
      position: relative;
      top: 100px; 
      visibility: hidden;
      }
 </style>

<a href="#01"> Go to link 01</a> 
  
<h2 id="01"> link 01</h2>

edit:: I think I miss read the online tutorial I was following. I have also tried this, but still can't get it to work.

<style>
   :target {
      display: block;
      position: relative;
      top: 100px; 
      margin: -100px 0;
      }
 </style>

<a href="#01"> Go to link 01</a> 

<h2 id="01"> link 01</h2>
like image 671
DarrenUK Avatar asked Dec 20 '25 12:12

DarrenUK


1 Answers

This seems to work.

:target:before {
    content: "";
    display: block;
    height: 100px;
    margin: -100px 0 0;
}
like image 165
DarrenUK Avatar answered Dec 22 '25 02:12

DarrenUK



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!