我想要一个Bootstrap 3导航栏,它有两行导航元素,并且navbar-brand跨越两行。在SM +屏幕尺寸上,两行都是可见的。在XS屏幕尺寸上,第二行折叠并显示要打开的图标栏。
SM +
+-------------------------------------------------------------------------------+
| | Nav-A-1 Nav-A-2 |
| SITE LOGO |---------------------------------------------------------------+
| | Nav-B-1 Nav-B-2 Nav-B-3 Nav-B-4 Form-Right |
+-------------------------------------------------------------------------------+
XS
+-------------------------------------------------------------------------------+
| | Nav-A-1 Nav-A-2 |
| SITE LOGO |---------------------------------------------------------------+
| | Nav-Collapsed Hamburger |
+-------------------------------------------------------------------------------+
如何使用导航栏完成此操作?
答案 0 :(得分:11)
您基本上可以使用两个导航栏,然后使用position: absolute
作为图像。您可能会使用网格,但您的折叠菜单最不可能在移动设备上实现全宽。
工作示例:
.navbar-inverse.nav-upper {
height: 50px;
}
.navbar-inverse.nav-upper ul {
float: right;
display: table;
}
.navbar-inverse.nav-upper .navbar-upper > li {
display: table-cell;
font-size: 14px;
}
.navbar-inverse.nav-upper .navbar-upper > li > a {
color: #777;
}
@media (min-width: 768px) {
.navbar.navbar-lower .navbar-nav {
margin-left: 100px;
}
}
.navbar-logo {
background-image: url('https://lh3.googleusercontent.com/-tw5LsU4Fg28/Umo6BBcoCnI/AAAAAAAAmjE/1iqULsem06E/w896-h896/heisencat.png');
width: 90px;
height: 90px;
background-size: cover;
background-position: center center;
background-repeat: no-repeat;
position: absolute;
top: 5px;
left: 15px;
z-index: 1051;
}

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<a class="navbar-logo" href="#"></a>
<nav class="navbar-inverse nav-upper">
<div class="container-fluid">
<ul class="nav navbar-upper">
<li><a href="#">NAV-A-1</a>
</li>
<li><a href="#">NAV-A-2</a>
</li>
</ul>
</div>
</nav>
<nav class="navbar navbar-inverse navbar-static-top navbar-lower">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" 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>
</div>
<div class="collapse navbar-collapse" id="navbar">
<ul class="nav navbar-nav">
<li><a href="#">NAV-B-1</a>
</li>
<li><a href="#">NAV-B-2</a>
</li>
<li><a href="#">NAV-B-3</a>
</li>
<li><a href="#">NAV-B-4</a>
</li>
</ul>
<form class="navbar-form navbar-right" role="search">
<div class="form-group">
<div class="input-group">
<input type="text" class="form-control" placeholder="Search">
<span class="input-group-btn">
<button type="submit" class="btn btn-default">Submit</button>
</span>
</div>
</div>
</form>
</div>
</div>
</nav>
&#13;
答案 1 :(得分:4)
试试这个。在SM +屏幕尺寸上,两行都是可见的。在XS屏幕尺寸上,第二行折叠并显示右侧打开的图标栏。
.navbar-default.nav-top ul {
display: inline-block;
float: right;
}
.navbar-default ul.navbar-top li {
float: left;
font-size: 11px;
}
.navbar-brand {
margin: -40px;
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
<nav class="navbar-default nav-top">
<div class="container-fluid">
<ul class="nav navbar-top" >
<li><a href="#">Nav-A-1</a>
</li>
<li><a href="#">Nav-A-2</a>
</li>
<li><a href="#">.....</a>
</li>
</ul>
</div>
</nav>
<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="#">
<img src="http://placehold.it/100x50/f00/f00">
</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 " style="margin-left:150px;">
<li class="active"><a href="#">Nav-B-1<span class="sr-only">(current)</span></a>
</li>
<li><a href="#">Nav-B-2</a>
</li>
<li><a href="#">Nav-B-3</a>
</li>
</ul>
</div>
</div>
</nav>
&#13;
答案 2 :(得分:1)
请查看下面的代码段
strtoupper()