【发布时间】:2020-08-05 04:22:16
【问题描述】:
我对 navbar-fixed-top 项目有疑问。它隐藏了容器中的内容。
这是通过添加以下css代码解决的常见问题:
body { padding-top: 70px; }
现在,当我加载页面时,容器不再被导航栏隐藏。问题是当我想使用href=#item 转到页面中的特定项目时。在这种情况下,该项目始终被导航栏隐藏。
我在Codeply 上创建了一个简单的代码来显示这个问题。在此示例中,当我单击“Got to test3”时,导航栏隐藏了项目<h2 class="font-weight-light">TEST3</h2>。
下面是代码:
<nav class="navbar navbar-expand-sm bg-dark navbar-dark fixed-top">
HELLO NAVBAR
</nav>
<div class="container py-2">
<div class="row">
<div class="col">
<div class="sidebar-sticky" id="menu">
<ul class="nav flex-column">
<li class="nav-item">
<a href="#test">Go to test1</a>
</li>
<li class="nav-item">
<a href="#test2">Go to test2</a>
</li>
<li class="nav-item">
<a href="#test3">Go to test3</a>
</li>
<li class="nav-item">
<a href="#test4">Go to test4</a>
</li>
</ul>
</div>
</div>
<div class="col">
<div id="test">
<h2 class="font-weight-light">TEST1</h2>
<p>
This is a Bootstrap starter example snippet.
</p>
<br/><br/><br/><br/><br/>
</div>
<div id="test2">
<h2 class="font-weight-light">TEST2</h2>
<p>
This is a Bootstrap starter example snippet.
</p>
<br/><br/><br/><br/><br/>
</div>
<div id="test3">
<h2 class="font-weight-light">TEST3</h2>
<p>
This is a Bootstrap starter example snippet.
</p>
<br/><br/><br/><br/><br/>
</div>
<div id="test4">
<h2 class="font-weight-light">TEST4</h2>
<p>
This is a Bootstrap starter example snippet.
</p>
<br/><br/><br/><br/><br/>
</div>
</div>
</div>
</div>
【问题讨论】:
-
嗨!您希望“不隐藏”哪些项目:右侧的
col和/或左侧的col(即粘性侧边栏)? -
@m1ck 我已经编辑了我的问题。如果您在示例中单击“Go to test3”,您将看到文本“test3”被隐藏
-
这能回答你的问题吗? Fixed page header overlaps in-page anchors
标签: html css bootstrap-4 navbar