Fixed page header overlaps in-page anchors

前端 未结 30 2806
逝去的感伤
逝去的感伤 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:43

    
    

    This code should do the trick. Swap out 45px for the height of your header bar.

    EDIT: If using jQuery is an option, I've also been successful using jQuery.localScroll with an offset value set. The offset option is a part of jQuery.scrollTo, which jQuery.localScroll is built upon. A demo is available here: http://demos.flesler.com/jquery/scrollTo/ (second window, under 'offset')

提交回复
热议问题