Fixed topbar vs named anchors

2019-04-07 08:49发布

I have a topbar with position:fixed which also contains anchor links (<a href="#someid">jdjd</a>).

The problem is that the target is placed in the top of the viewport (behind the fixed topbar).

how can I fix so the the browser scrolls so that the target is shown just below the topbar?

2条回答
兄弟一词,经得起流年.
2楼-- · 2019-04-07 09:34

Not sure why you're being downvoted, it seems like an honest a good question.

I'd put a margin-top on the viewport, equal to the height of the fixed topbar.

http://jsfiddle.net/justiceerolin/KfMLJ/ as an example

查看更多
Deceive 欺骗
3楼-- · 2019-04-07 09:38

As far as i know there is no clean soloution. If you use inline scrollbar it can be achieved, but it needs a fixed height then.

2 soloutions found using CSS: http://css-tricks.com/hash-tag-links-padding/

Else you could pretty easy use JQUERY to measure the users height, put it into a container div, and have scrolling on that.

See: http://jsfiddle.net/jpGdu/

Another soloution could be giving the element ur linking to a padding top (if it's h1 or whatever) :)

查看更多
登录 后发表回答