我有一个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
我在阅读Twitter bootstrap responsive navigation disappears after opening and closing
后将height: auto !important; overflow: visible !important;
添加到.nav-collapse.collapse
问题仍然存在。
答案 0 :(得分:1)
您的问题中不清楚,但是当您的视口缩小时,您错过了切换按钮来打开和关闭菜单,否则移动菜单将始终打开。
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>
答案 1 :(得分:0)
只需删除collapse
div#navbar
课程即可
这是fiddle
<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">
<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>
并重写xs视图的css