问题:
If I have a non-scrolling header in an HTML page, fixed to the top, having a defined height:如果我在 HTML 页面中有一个非滚动标题,固定在顶部,具有定义的高度:
Is there a way to use the URL anchor (the #fragment
part) to have the browser scroll to a certain point in the page, but still respect the height of the fixed element without the help of JavaScript ?有没有办法使用 URL 锚点( #fragment
部分)让浏览器滚动到页面中的某个点,但在没有 JavaScript 帮助的情况下仍然尊重固定元素的高度?
http://example.com/#bar
WRONG (but the common behavior): CORRECT: +---------------------------------+ +---------------------------------+ | BAR///////////////////// header | | //////////////////////// header | +---------------------------------+ +---------------------------------+ | Here is the rest of the Text | | BAR | | ... | | | | ... | | Here is the rest of the Text | | ... | | ... | +---------------------------------+ +---------------------------------+
解决方案:
参考一: https://en.stackoom.com/question/H8yx参考二: https://stackoom.com/question/H8yx