Affixed header overlap solution causing other overlap issues

时间秒杀一切 提交于 2020-01-25 20:36:06

问题


I'm trying to create an affixed header using Bootstrap's Affix. I've got my nav bar to affix properly, but I then run into an issue when I user anchor links; the nav bar overlaps the anchor link text when it first loads up. I've found a solution to that here, and in particular I'm using this comment (because I want the anchor text to be visible).

However, that solution makes the link be placed on top of the html before the anchor link, meaning that if I click anywhere there I end up inadvertently clicking on the link. I tried adding a z-index: -10000;, but that didn't seem to have any effect.

How else can I either hide the anchor link behind other HTML, or get the affixed navbar to not appear over my anchor link text?

Here is the simplified version of what I currently have:

HTML:

<div class="nav" data-spy="affix" data-offset-top="1" data-offset-bottom="200">
    ....
</div>
...
<a class="anchor" name="link" href="#link">link text</a>

CSS:

a.anchor:before {
    content: '';
    display: block;
    position: relative;
    width: 0;
    height: 1em;
    margin-top: -1em;
}

来源:https://stackoverflow.com/questions/29101754/affixed-header-overlap-solution-causing-other-overlap-issues

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!