gpt4 book ai didi

html - Bootstrap Nav 在调整大小时消失

转载 作者:行者123 更新时间:2023-11-28 16:33:56 24 4
gpt4 key购买 nike

我有一个 Bootstrap 3 导航栏。当我将浏览器窗口缩放到低分辨率或使用我的手机访问页面时,我没有菜单。通常,使用 Bootstrap 我有一个折叠的导航,但无处可寻。

这是 HTML:

<nav class="navbar navbar-default navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<a class="navbar-brand" href="index.php"><img src="images/logo.png"></a>
</div>

<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-right">
<li><a href="index.php">Home</a></li>
<li class="aktiv" ><a href="advertiser.php">Advertisers</a></li>
<li><a href="publisher.php">Publishers</a></li>
<li><a href="#" data-toggle="modal" data-target="#aboutModal">About</a></li>
<li><a href="#" data-toggle="modal" data-target="#pressModal">Press</a></li>
</ul>
</div>
</div>
</nav>

CSS:

.navbar {
background-color: #333E48;
border: 0;
display: block!important; /* From Stack Overflow */
}

.navbar-brand > img,
.navbar-brand {
padding:0px;
margin:0;
}

.navbar-brand > img {
padding: 4px;
height: 50px;
margin: auto;
vertical-align: middle;
display: inline-block;
}

.navbar-brand,
.navbar-nav li a {
line-height: 90px;
height: 90px;
padding-top: 0px;
}

.nav-collapse.collapse {
height: auto !important; /* From Stack Overflow */
overflow: visible !important; /* From Stack Overflow */
}

我在阅读 Nav disappears after resize 后将 display: block!important; 添加到 .navbar

我添加了 height: auto !important; overflow: visible !important; to .nav-collapse.collapse 阅读后 Twitter bootstrap responsive navigation disappears after opening and closing

问题仍然存在。

最佳答案

您的问题中并不清楚,但是您缺少在视口(viewport)缩小时打开和关闭菜单的切换按钮,否则移动菜单将始终打开。

nav.navbar-default  {
background: #333E48;
border: 0;
}
.navbar-default .navbar-brand > img,
.navbar-default .navbar-brand {
padding: 0px;
margin: 0;
}
.navbar-default .navbar-brand > img {
padding: 4px;
height: 50px;
margin: auto;
vertical-align: middle;
display: inline-block;
}
.navbar-default .navbar-brand,
.navbar-default .navbar-nav li a {
line-height: 90px;
height: 90px;
padding-top: 0px;
}
.navbar-default .nav-collapse.collapse {
height: auto !important;
/* From Stack Overflow */
overflow: visible !important;
/* From Stack Overflow */
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-collapse" aria-expanded="false"> <span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>

</button>
<a class="navbar-brand" href="index.php">
<img src="http://placehold.it/100x50/fff/fff" />
</a>

</div>
<div class="collapse navbar-collapse" id="bs-collapse">
<ul class="nav navbar-nav navbar-right">
<li><a href="index.php">Home</a>

</li>
<li class="aktiv"><a href="advertiser.php">Advertisers</a>

</li>
<li><a href="publisher.php">Publishers</a>

</li>
<li><a href="#" data-toggle="modal" data-target="#aboutModal">About</a>

</li>
<li><a href="#" data-toggle="modal" data-target="#pressModal">Press</a>

</li>
</ul>
</div>
</div>
</nav>

关于html - Bootstrap Nav 在调整大小时消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31810595/

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