答案 0 :(得分:0)
这是一种方式
<强> Bootply 强>
<强> CSS 强>
@media screen and (max-width: 768px) {
#mymenu{
background-color: #f8f8f8;
}
.navbar-header{
display: inline-block;
z-index: 2;
position: absolute
}
.navbar-right{
z-index:1
position:absolute;
width:100%;
top:0;
left:0;
margin-top:0;
}
}
.navbar-toggle{display: block !important;}
<强> HTML 强>
<nav class="navbar navbar-default">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<a class="navbar-brand" href="#">Brand</a>
</div>
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
<button type="button" id="mybtn" class="dropdown-toggle navbar-toggle collapsed" data-toggle="dropdown" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar visible-xs"></span>
<span class="icon-bar visible-xs"></span>
<span class="icon-bar visible-xs"></span>
<span class="hidden-xs">Toggle</span>
</button>
<ul class="dropdown-menu" id="mymenu">
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li><a href="#">Something else here</a></li>
<li role="separator" class="divider"></li>
<li><a href="#">Separated link</a></li>
</ul>
</li>
</ul>
</div><!-- /.container-fluid -->
</nav>
<强> Bootply 强>
<强>的CSS 强>
@media screen and (max-width: 768px) {
#mymenu{
background-color: #f8f8f8;
}
.navbar-header{
display: inline-block;
z-index: 2;
position: absolute
}
.navbar-right{
z-index:1;
position:absolute;
top:0;
right:15px;
margin-top:0;
}
}
.navbar-toggle{display: block !important;}