我对Bootstrap Navbar中按钮的大小/宽度有疑问。我尝试在我的主CSS文件中将每个宽度设置为50%,以便它适合Nav,我仍然没有运气。似乎链接之间有很多空间我想摆脱它。有人能帮我弄清楚我做错了吗?
HTML
<nav class="navbar navbar-default navbar-fixed-top" role="navigation" bs-navbar>
<div class="navbar-header">
<a class="navbar-brand navbar-left" href="#">Brand</a>
</div>
<ul class="nav nav-justified navbar-right">
<li data-match-route="/$"><a href="#/" a id="HomeNav">Home</a></li>
<li data-match-route="/page-one"><a href="#/page-one" id="PageOne">Page One</a></li>
<li data-match-route="/page-two.*"><a href="#/page-two/sub-a" id="PageTwo">Page Two</a></li>
<li>
<a class="btn btn-sm btn-secondary-outline" href="/users/sign_up" id="SignUp">SIGN UP</a>
</li>
<li>
<a class="btn btn-sm btn-primary-outline" href="/users/sign_in" id="SignIn">SIGN IN</a>
</li>
<li>
<a class="btn btn-sm btn-gray-outline" href="/professionals/sign_in" id="People">People</a>
</li>
</ul>
</nav>
CSS
#HomeNav {
max-width: 50%;
}
(例如)
答案 0 :(得分:0)
也许这很有帮助。如果您尝试使用均匀间隔或对齐的链接,则可能需要添加。
您可以将显示更改为table-cell并从导航栏中删除浮动。
请参阅工作示例代码段。
@media (min-width: 767px) {
.navbar.navbar-custom .navbar-nav {
margin: 0;
display: table;
width: 100%;
}
.navbar.navbar-custom .navbar-nav > li {
display: table-cell;
float: none;
}
.navbar.navbar-custom .navbar-nav > li > a {
text-align: center;
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.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-custom" role="navigation">
<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-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="bs-navbar">
<ul class="nav navbar-nav">
<li data-match-route="/$"><a href="#/" a id="HomeNav">Home</a>
</li>
<li data-match-route="/page-one"><a href="#/page-one" id="PageOne">Page One</a>
</li>
<li data-match-route="/page-two.*"><a href="#/page-two/sub-a" id="PageTwo">Page Two</a>
</li>
<li> <a class="nav-btn btn-secondary-outline" href="/users/sign_up" id="SignUp">SIGN UP</a>
</li>
<li> <a class="nav-btn btn-primary-outline" href="/users/sign_in" id="SignIn">SIGN IN</a>
</li>
<li> <a class="nav-btn btn-gray-outline" href="/professionals/sign_in" id="People">People</a>
</li>
<li> <a class="nav-btn btn-gray-outline" href="/professionals/sign_in" id="People">People</a>
</li>
<li> <a class="nav-btn btn-gray-outline" href="/professionals/sign_in" id="People">People</a>
</li>
<li> <a class="nav-btn btn-gray-outline" href="/professionals/sign_in" id="People">People</a>
</li>
</ul>
</div>
</div>
</nav>
答案 1 :(得分:0)
很简单,您的<ul>
代码设置不正确,请将其更改为此<ul class="nav navbar-nav">
HTML:
<nav class="navbar navbar-default navbar-fixed-top" role="navigation" bs-navbar>
<div class="navbar-header">
<a class="navbar-brand navbar-left" href="#">Brand</a>
</div>
<ul class="nav navbar-nav">
<li data-match-route="/$"><a href="#/" a id="HomeNav">Home</a></li>
<li data-match-route="/page-one"><a href="#/page-one" id="PageOne">Page One</a></li>
<li data-match-route="/page-two.*"><a href="#/page-two/sub-a" id="PageTwo">Page Two</a></li>
<li>
<a class="btn btn-sm btn-secondary-outline" href="/users/sign_up" id="SignUp">SIGN UP</a>
</li>
<li>
<a class="btn btn-sm btn-primary-outline" href="/users/sign_in" id="SignIn">SIGN IN</a>
</li>
<li>
<a class="btn btn-sm btn-gray-outline" href="/professionals/sign_in" id="People">People</a>
</li>
</ul>
</nav>