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

在我的网站上,我具有带有固定导航栏的Bootstrap 3主题。

某些文本被导航栏隐藏。

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

benxiaolai 回答:如何在锚链接上创建偏移量?

在样式: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>

本文链接:https://www.f2er.com/3152000.html

大家都在问