gpt4 book ai didi

html - 折叠的导航栏仅显示在小屏幕尺寸的 Bootstrap 上

转载 作者:太空宇宙 更新时间:2023-11-04 08:26:25 25 4
gpt4 key购买 nike

我正在尝试实现一个在小型设备上折叠的导航栏。这工作正常。

但是,在中型和大型屏幕上,导航栏根本不显示。我希望导航栏对于中型和大型屏幕看起来像普通导航栏,然后折叠成小型设备的导航栏按钮。我正在遵循 Bootstrap 模板,但不知道为什么导航栏根本不显示。

  <div class = "container">

<nav class="navbar navbar-default" >
<div class="navbar-header">
<a class="navbar-brand" href="#">
<img alt="logo" src="logo.png" width="250px;">
</a>
<button class="navbar-toggle collapsed" type="button" data-toggle="collapse" data-target="#collapse-navbar" aria-expanded="false" aria-controls="navbar">
&#9776;
</button>
</div>
<div class="navbar-collapse collapse" id="collapse-navbar">
<ul class="nav navbar-nav">
<li class= "nav-item"><a class= "nav-link active" href="#">Home</a></li>
<li class= "nav-item"><a class= "nav-link" href="#">Build</a></li>
<li class= "nav-item"><a class= "nav-link" href="#">About</a></li>
</ul>
</div>
</nav>
</div>

这是一个代码笔链接:https://codepen.io/gkunthara/pen/VWdrYj

最佳答案

您正在使用 bootstrap 3 标记并链接到 bootstrap 4 css 或者链接到 bootstrap 3 的 css 和 javascript,如下所示:

<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>

或者像这样将导航栏标记更改为 bootstrap 4 的标记:

<nav class="navbar navbar-toggleable-md navbar-light bg-faded">
<button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<a class="navbar-brand" href="#">
<img alt="logo" src="logo.png" width="250px;">
</a>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item active">
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Build</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">About</a>
</li>
</ul>
</div>
</nav>

关于html - 折叠的导航栏仅显示在小屏幕尺寸的 Bootstrap 上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45134420/

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