Div anchors scrolling too far

后端 未结 5 1554
旧巷少年郎
旧巷少年郎 2020-12-25 11:53

I\'m using a static bar at the top of my site, about 20px high. When I click an anchor link(for those who don\'t know, the navigation on wikipedia works like that. Click a t

5条回答
  •  太阳男子
    2020-12-25 12:25

    CSS-only: it's a little dirty, but :target {padding-top: 20px;} would work if you are linking to a block element (I assumed you do, since your question says div). However, it might not look so good when you scroll manually afterwards. Example http://dabblet.com/gist/3121729

    Still, I think that using a bit of JavaScript to fix this would be nicer.

提交回复
热议问题