Bootstrap 更改导航栏字体大小
Posted
技术标签:
【中文标题】Bootstrap 更改导航栏字体大小【英文标题】:Bootstrap change the navbar font-size 【发布时间】:2016-01-28 23:59:53 【问题描述】:我浪费了 2 个小时来寻找解决方案。我想更改导航栏的字体大小,甚至在媒体查询中也更改字体大小。我可以更改颜色而不是字体,有时col-lg
中的字体会更改大小,但media-queries
中的字体不会更改
HTML
<nav class="navbar navbar-default">
<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>
</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="#">Home<span class="sr-only">(current)</span></a></li>
<li> <a class="nav-links" href="aboutus.html"><span style="white-space: nowrap">About Us</span></a> </li>
<li> <a class="nav-links" href="whoweare.html"><span style="white-space: nowrap">Who We Are</span></a> </li>
<li> <a class="nav-links" href="mission.html">Mission</a> </li>
<li> <a class="nav-links" href="activities.html">Activities</a> </li>
<li> <a class="nav-links" href="gallery.html">Gallery</a> </li>
<li> <a class="nav-links" href="donate.html">Donate</a> </li>
<li> <a class="nav-links" href="sitemap.html">Sitemap</a> </li>
<li> <a class="nav-links" href="contactus.html"><span style="white-space: nowrap">Contact Us</span></a> </li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
CSS
nav
width: 100%;
height: 40px;
background: -webkit-linear-gradient(#3f9a15, #388813, #3f9a15, #388813, #3f9a15);
background: -o-linear-gradient(#3f9a15, #388813, #3f9a15, #388813, #3f9a15);
background: linear-gradient(#3f9a15, #388813, #3f9a15, #388813, #3f9a15);
border-radius: 6px !important;
-moz-border-radius: 6px !important;
.nav a
color: white !important;
font-size: 1.8em !important;
【问题讨论】:
看看这个jsfiddle 你的代码,font-size
运行良好。
@MikeRoss 如何给它添加填充,padding-right
填充到什么?我猜两边都填充到nav-bar
对吧?
链接之间,媒体查询中的字体不会改变@media only screen and (min-width : 992px) (max-width : 768px) header .header-icons-list font-size: 1.1em; .navbar a font-size: 10px !important .message font-size: 1em;
【参考方案1】:
考虑到您希望在链接 Home
和 About
等之间使用 padding-right
,这是一个有效的 demo。
对于链接,我使用了css
类.nav li
nav
width: 100%;
height: 40px;
background: -webkit-linear-gradient(#3f9a15, #388813, #3f9a15, #388813, #3f9a15);
background: -o-linear-gradient(#3f9a15, #388813, #3f9a15, #388813, #3f9a15);
background: linear-gradient(#3f9a15, #388813, #3f9a15, #388813, #3f9a15);
border-radius: 6px !important;
-moz-border-radius: 6px !important;
.nav a
color: white !important;
font-size: 1.8em !important;
.nav li
padding-right:5px;
【讨论】:
以上是关于Bootstrap 更改导航栏字体大小的主要内容,如果未能解决你的问题,请参考以下文章