我的Navbar存在一些问题。它崩溃了< 768px但是从768开始它会做这个愚蠢的事情,直到它可以正确填充页面:
我尝试将 nav-justified 输入HTML,但它只是堆叠每个按钮。
理想情况下,我正在寻找任何看起来并不愚蠢的解决方案,但遗憾的是我需要在此菜单上保留每一个链接,以便剔除一些不是一个选项。
我认为最好的办法是让它全部居中对齐,这样如果必须叠加它至少在中间。
其他人之前有过这个问题吗?
答案 0 :(得分:2)
以下是解决此问题的几种方法。
1)减小字体大小
2)利用下拉菜单。
3)为频繁/公共链接添加另一个(永久暴露的)栏。
参见工作示例。
.navbar.navbar-custom,
.navbar.navbar-custom2,
.navbar.navbar-custom3 {
background: white;
border-radius: 0;
border: none;
border-bottom: 3px solid red;
}
/**NAV One**/
.navbar.navbar-custom .navbar-nav > li > a {
font-size: 12px;
}
/**NAV Three**/
.navbar-default.nav-top {
background: white;
border-top: 3px solid red;
}
.navbar-default.nav-top ul {
display: inline-block;
float: right;
}
.navbar-default .navbar-top li {
float: left;
font-size: 12px;
}
.navbar-default .navbar-top li a {
color: #555;
}
<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 navbar-default navbar-custom">
<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-nv1" 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="#">NAV 1</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-nv1">
<ul class="nav navbar-nav">
<li><a href="#">HOME</a>
</li>
<li><a href="#">TRAINING</a>
</li>
<li><a href="#">HEALTH</a>
</li>
<li><a href="#">SAFETY</a>
</li>
<li><a href="#">TRAINING CALENDAR</a>
</li>
<li><a href="#">ABOUT</a>
</li>
<li><a href="#">CONTACT</a>
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container-fluid -->
</nav>
<hr>
<div class="alert alert-info">NAV One + Smaller Text</div>
<nav class="navbar navbar-default navbar-custom2">
<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-nv2" 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="#">NAV 2</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-nv2">
<ul class="nav navbar-nav">
<li><a href="#">HOME</a>
</li>
<li><a href="#">TRAINING CALENDAR</a>
</li>
<li><a href="#">ABOUT</a>
</li>
<li><a href="#">CONTACT</a>
</li>
<li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">SERVICES <span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="#">TRAINING</a>
</li>
<li><a href="#">HEALTH</a>
</li>
<li><a href="#">SAFETY</a>
</li>
</ul>
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container-fluid -->
</nav>
<hr>
<div class="alert alert-danger">NAV Two + Dropdown</div>
<nav class="navbar-default nav-top">
<div class="container-fluid">
<ul class="nav navbar-top">
<li><a href="#">ABOUT</a>
</li>
<li><a href="#">CONTACT</a>
</li>
</ul>
</div>
</nav>
<nav class="navbar navbar-default navbar-custom3">
<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-nv3" 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="#">NAV 3</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-nv3">
<ul class="nav navbar-nav">
<li><a href="#">HOME</a>
</li>
<li><a href="#">TRAINING</a>
</li>
<li><a href="#">HEALTH</a>
</li>
<li><a href="#">SAFETY</a>
</li>
<li><a href="#">TRAINING CALENDAR</a>
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container-fluid -->
</nav>
<hr>
<div class="alert alert-warning">NAV Three + Upper Links</div>
答案 1 :(得分:1)
是否就像将@media查询更高一样简单,如800-900左右?然后按照vanburenx的建议将其更改为下拉菜单?