固定页眉在页定位中重叠

如果我在HTML页面中有一个非滚动标题,该标题固定在顶部并具有定义的高度:

有没有一种方法可以使用URL锚点(该#fragment部分)使浏览器滚动到页面中的某个点,但是在

仍然可以尊重固定元素的高度?

http://foo.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 |

| ... | | ... |

+---------------------------------+ +---------------------------------+

回答:

我有同样的问题。我通过将一个类添加到锚元素(顶部栏高度为padding-top值)来解决此问题。

<h1><a class="anchor" name="barlink">Bar</a></h1>

然后简单的CSS:

.anchor { padding-top: 90px; }

以上是 固定页眉在页定位中重叠 的全部内容, 来源链接: utcz.com/qa/417147.html

回到顶部