Fixed page header overlaps in-page anchors

前端 未结 30 2832
逝去的感伤
逝去的感伤 2020-11-22 00:25

If I have a non-scrolling header in an HTML page, fixed to the top, having a defined height:

Is there a way to use the URL anchor (the #fragment part) t

30条回答
  •  遇见更好的自我
    2020-11-22 00:39

    I wasn't having any luck with the answer listed above and ended up using this solution which worked perfectly...

    Create a blank span where you want to set your anchor.

    
    

    And apply the following class:

    .anchor {
      display: block;
      height: 115px;       /* same height as header */
      margin-top: -115px;  /* same height as header */
      visibility: hidden;
    }
    

    This solution will work even if the sections have different colored backgrounds! I found the solution at this link.

提交回复
热议问题