CSS To Make Vertical Scrolling Region Under Fixed Header?

前端 未结 3 1056
耶瑟儿~
耶瑟儿~ 2020-12-22 01:03

Goal: Emulate the fixed header and scrollable content of this StackOverflow page:

  • Footer under the content scrolls up as the content
3条回答
  •  梦毁少年i
    2020-12-22 01:46

    Here's a trick to make the anchor seem bigger so that clicking the link will not cover the actual anchor text. Since you have negative margin, the anchor element will not take up more space. But it will have a scroll position that is 50px taller.

    :target {
      padding-top: 50px; 
      margin-top: -50px
    }
    

    This uses the :target pseudo-class.

    The :target CSS pseudo-class represents a unique element (the target element) with an id matching the URL's fragment.

    Example: https://codepen.io/haakenlid/pen/oyarva

提交回复
热议问题