Is there a way to margin an anchor in css?

前端 未结 5 1105
你的背包
你的背包 2021-02-12 12:18

I have a fixed header height 50px. In my body, I have a lot of anchors. The problem is that, when I click on links pointing to anchors, the anchor appears under my fixed header

5条回答
  •  深忆病人
    2021-02-12 12:39

    It is an old thread, i know - but maybe other people has the same question.

    An Opportunity is setting a top padding to each anchored div like this:

    .box{ padding-top: 50px; ... }

    Now your anchor scroll will reach the box without any empty containers before, and the padding you add in CSS will give you the space to show the content directly under your header.

提交回复
热议问题