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

问题描述 投票:-1回答:1

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

某些文本被导航栏隐藏。

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

html css hyperlink anchor href
1个回答
0
投票

在样式: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>
© www.soinside.com 2019 - 2024. All rights reserved.