Fixed page header overlaps in-page anchors

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

    Implemented using :before worked great until we realized that the pseudo element was actually covering and blocking pointer events that sat within the pseudo element's area. Using something like pointer-events: none on the :before or even directly on the anchor had no affect.

    What we ended up doing was making the anchor's positioning absolute and then adjusting it's position to be the offset/height of the fixed area.

    Offset Anchor without Blocking Pointer Events

    .section-marker {
    
        position: absolute;
        top: -300px;
    }
    

    The value with this is that we're not blocking any elements that might fall within those 300px. The downside is that grabbing that element's position from Javascript needs to take into account that offset so any logic there had to be adjusted.

提交回复
热议问题