我试图让图标垂直居中,以便与导航链接的其余部分保持一致,但无论我尝试什么,我似乎无法让它发挥作用。
HTML
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<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>
<img src="img/logo.png" class="navbar-brand" href="index.html">
</div>
<div class="collapse navbar-collapse" id="nav">
<ul class="nav navbar-nav navbar-left">
<li><span class="fa fa-phone"> +62 202 555 0117</span></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Work</a></li>
<li><a href="#">Blog</a></li>
<li><a href="#">Contact</a></li>
</ul>
</div>
</div>
</nav>
CSS
nav.navbar {
padding: 12px;
}
span.fa.fa-phone {
color: #fff;
vertical-align: middle;
}
答案 0 :(得分:2)
Navbar的链接具有padding: 15px
属性。因此,您需要将此属性应用于电话号码。
为此目的制作特殊课程。使用
<li class="phone"><span class="fa fa-phone"></span> +62 202 555 0117</li>
而不是<li><span class="fa fa-phone"> +62 202 555 0117</span></li>
。
使用<a class="navbar-brand" href="index.html"><img src="img/logo.png" alt=""></a>
而不是<img src="img/logo.png" class="navbar-brand" href="index.html">
切换按钮必须使用id
中的<div class="collapse navbar-collapse" id="nav">
作为data-target
属性的值。
请查看结果。这是你想要实现的目标吗?
@import url('https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css');
@import url('https://maxcdn.bootstrapcdn.com/font-awesome/4.6.1/css/font-awesome.min.css');
.navbar {
padding: 12px;
}
.nav .phone {
color: #fff;
padding: 15px;
}
&#13;
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#nav" 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="index.html"><img src="img/logo.png" alt=""></a>
</div>
<div class="collapse navbar-collapse" id="nav">
<ul class="nav navbar-nav navbar-left">
<li class="phone"><span class="fa fa-phone"></span> +62 202 555 0117</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Work</a></li>
<li><a href="#">Blog</a></li>
<li><a href="#">Contact</a></li>
</ul>
</div>
</div>
</nav>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
&#13;