Anchor links to start below the header which is fixed at the top

后端 未结 4 1730
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-01 20:08

I have a page which has a fixed header at the top, which is 63px in height. below this I have different sections of the page (divs) which are in essence separate pages. Each sec

4条回答
  •  眼角桃花
    2021-02-01 20:42

    Ive got an even better solution to this problem.

    • Firstly in the css a class can be created (call it whatever you want)

    .anchor{
       display:block;
       height:63px; /* this is the height of your header */
       margin-top:-63px; /* this is again negative value of the height of your header */
       visibility:hidden;
    }
    

    • In the HTML just before your actual div section starts, for example mine is #landingcontainer you should add a span tag with the class of anchor (which we made above) and an id of whatever you want. for me I did this :

    
    

    Then the actual link will not now be linked to your actual div id of the section you want to take them to, but rather the id of the span tag must be given in the link.

    HOME
    

    AND THERE YOU HAVE IT!

    what we are doing here in essence is making the browser stop where the span starts which is exactly the height of the header, which then makes the viewer non the wiser ;)

提交回复
热议问题