gpt4 book ai didi

html - 使 Bootstrap Nav 置顶

转载 作者:太空宇宙 更新时间:2023-11-04 00:45:46 28 4
gpt4 key购买 nike

我正在使用 Bootstrap 和导航栏制作一个网站以保持在顶部,但是使用类 sticky-top 似乎没有做任何事情。

这是导航的代码:

<div class="row">
<div class="col-md-12">
<ul class="nav justify-content-center sticky-top">
<li class="nav-item">
<a class="nav-link active" href="#">Active</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
</ul>
</div>
</div>

希望有人能帮忙!

最佳答案

您需要将 sticky-top 放到导航栏的容器中,如果该 row 是导航栏,那么您需要将它放在那里而不是它的子项。

/* For displaying */
body {
height: 300vh;
background-image: linear-gradient(to bottom, white, black);
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">

<!-- You need to move sticky-top to the outer element of navbar, which is here -->
<div class="row sticky-top">
<div class="col-md-12">
<ul class="nav justify-content-center">
<li class="nav-item">
<a class="nav-link active" href="#">Active</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
</ul>
</div>
</div>

关于html - 使 Bootstrap Nav 置顶,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57246463/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com