简体   繁体   English

HTML相对链接链接到导航栏覆盖的锚点

[英]HTML relative link links to the anchor covered by the navbar

When I create a relative link in HTML, <a href="workshops.html#bot" class="btn btn-primary">Bot Workshops</a> it links properly, but places the anchor at the top of the page, covered by a navigation bar. 当我在HTML中创建相对链接时, <a href="workshops.html#bot" class="btn btn-primary">Bot Workshops</a>可以正确链接,但是将锚点放在页面顶部,被导航栏覆盖。 Is there a way to make it be lower so that the anchor is underneath the navbar? 有没有办法降低它,使锚点位于导航栏下面?

If I understand it correctly, when the user clicked <a href="workshops.html#bot" class="btn btn-primary">Bot Workshops</a> , it should go underneath the navbar. 如果我正确理解,则当用户单击<a href="workshops.html#bot" class="btn btn-primary">Bot Workshops</a> ,它应该位于导航栏的下方。

In your navbar, add an id. 在您的导航栏中,添加一个ID。 For example: 例如:

<div id="bot"></div>

Maybe you need to change the display of the anchor link. 也许您需要更改锚链接的显示。

a {
    display: block;
    ...
}

You should add a padding-top to the #bot div (approx the height of the navbar plus some space). 您应该在#bot div中添加一个padding-top (大约是导航栏的高度加上一些空间)。 (This is based on some assumptions below) (这是基于以下一些假设)

I think your navbar is fixed? 我认为您的导航栏是固定的吗?

If that is the case, the top of the #bot anchor div will be on the top-edge of the browser viewport. 在这种情况下,#bot锚点div的顶部将位于浏览器视口的顶部。 But the navbar will be obfuscating some of that content underneath. 但是导航栏将混淆下面的某些内容。

This is more of a css/styling issue. 这更多是css /样式问题。

If you do add a padding-top, you might also want to make sure that value is responsive. 如果确实添加了padding-top,则可能还需要确保该值具有响应性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM