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

后端 未结 4 1731
爱一瞬间的悲伤
爱一瞬间的悲伤 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:19

    I have a pageful of

    tags and so there's no preset/predictable height on the elements. The solution that worked best--without wreaking havoc on the rest of the established CSS/layout--was this one from CSS-tricks:

    div#container p.paragraph:before {
      content: " "; 
      margin-top: -180px; 
      height: 180px; 
      visibility: hidden; 
    }
    

    Nothing else needed.

    (FYI to anyone who is thinking of using this solution: it works as long as you don't need anything in the affected element to be clickable/selectable as this method appears to mess with actual on-screen position of things. But fine for casual browsing.)

提交回复
热议问题