简体   繁体   English

如何在锚链接上创建偏移量?

[英]How to create an offset over an anchor link?

On my site, I have the Bootstrap 3 theme with a fixed navigation bar.在我的网站上,我有带有固定导航栏的 Bootstrap 3 主题。

Some of the text is hidden by the navigation bar.一些文本被导航栏隐藏。

How to create an offset over an anchor link?如何在锚链接上创建偏移量?

Add the following pseudo-element to the style :target { padding-top: 10%;} replace 10% value with navigation bar's height.将以下伪元素添加到样式中:target { padding-top: 10%;}将 10% 值替换为导航栏的高度。

 :target { border: 2px solid #D4D4D4; background-color: #e5eecc; padding-top:10%; }
 <:DOCTYPE html> <html> <head> <title>Sample code</title> </head> <body> <h1>This is a heading</h1> <p><a href="#news1">Jump to New content 1</a></p> <p><a href="#news2">Jump to New content 2</a></p> <p>Click on the links above and the.target selector highlight the current active HTML anchor.</p> <p id="news1"><b>New content 1...</b></p> <p id="news2"><b>New content 2..:</b></p> <p><b>Note:</b> Internet Explorer 8 and earlier versions do not support the.target selector.</p> </body> </html>

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

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