当我在移动电话尺寸上调整屏幕大小时,我希望导航栏保持在导航栏的右侧。
<nav class="navbar navbar-default" id="admin_nav">
<div class="container-fluid">
<div class="navbar-header">
<a href="#" class="navbar-brand" id="side_menu"><i class="fa fa-bars" aria-hidden="true"></i></a>
</div>
<ul class="nav navbar-nav navbar-right">
<li><a href="#"><i class="fa fa-user" aria-hidden="true"></i> Welcome, Admin</a></li>
</ul>
</div>
</nav>
答案 0 :(得分:0)
将white-space:nowrap
添加到ul
<nav class="navbar navbar-default" id="admin_nav">
<div class="container-fluid">
<div class="navbar-header">
<a href="#" class="navbar-brand" id="side_menu"><i class="fa fa-bars" aria-hidden="true"></i></a>
</div>
<ul class="nav navbar-nav navbar-right" style="white-space: nowrap">
<li><a href="#"><i class="fa fa-user" aria-hidden="true"></i> Welcome, Admin</a></li>
</ul>
</div>
</nav>
答案 1 :(得分:0)
使用此代码
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<nav class="navbar navbar-default">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" 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="#">Brand</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="active"><a href="#">Link <span class="sr-only">(current)</span></a></li>
<li><a href="#">Link</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>
<ul class="dropdown-menu">
<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>
<li role="separator" class="divider"></li>
<li><a href="#">One more separated link</a></li>
</ul>
</li>
</ul>
<form class="navbar-form navbar-left">
<div class="form-group">
<input type="text" class="form-control" placeholder="Search">
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
<ul class="nav navbar-nav navbar-right">
<li><a href="#">Link</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>
<ul class="dropdown-menu">
<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><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
答案 2 :(得分:0)
为了在移动视图中识别折叠导航栏项目和固定导航栏项目的区别,我添加了两种方式以了解它的应用方式。我正在使用bootstrap版本3.3.7
.navmenu-mobile {
position: absolute;
right: 80px;
top: 15px;
text-align: center;
}
@media (min-width: 768px) {
.logo-center {
position: absolute;
width: 100%;
left: 0;
text-align: center;
margin: auto;
}
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<nav class="navbar navbar-default">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<div class="logo-center navbar-brand">
<a href="/">Brand</a>
</div>
<ul class="list-inline visible-xs navmenu-mobile" style="">
<li><a href="#">Right Nav</a></li>
<li><a href="#">Right Nav</a></li>
</ul>
</div>
<div id="navbar" class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li class="dropdown">
<a href="#" class="dropdown-toggle banner-dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Week<span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="#">Sunday</a></li>
</ul>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li class="hidden-xs"><a href="#">docs</a></li>
<li class="hidden-xs"><a href="#">help</a></li>
<li>
<a href="#" class="dropdown-toggle banner-username-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Welcome <span class="caret"></span></a>
<ul class="dropdown-menu dropdown-menu-right">
<li><a href="#" class="banner-dropdown-link">Your Info</a></li>
<li role="separator" class="divider"></li>
<li><a href="#" class="banner-dropdown-link">Logout</a></li>
</ul>
</li>
</ul>
</div>
</div>
</nav>
&#13;