2016-02-17 203 views
0

所以我有bootstrap navbar這是固定的,並有身體填充頂部:50px; 到目前爲止這麼好,但bootstrap.js和.css文件使得點擊李背景色爲白色,我希望它是黑色的我猜默認值是white.So我試圖手動更改.active的背景顏色屬性類bootstrap導航欄更改主動李背景顏色手動

HTML:

<header> 
<nav class="navbar navbar-fixed-top"> 
    <div class="container"> 
     <div class="navbar-header"> 
     <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar"> 
      <span class="icon-bar"></span> 
      <span class="icon-bar"></span> 
      <span class="icon-bar"></span> 
     </button> 
     <a class="navbar-brand" href="#"><img id="logo-img" src="images/logo.png" alt="logo"></a> 
     </div> 
     <div class="collapse navbar-collapse" id="myNavbar"> 
     <ul class="nav navbar-nav"> 
      <li class="active"><a href="#">Home</a></li> 
      <li><a href="#"><span class="glyphicon glyphicon-search"></span> Search</a></li> 
      <li><a href="#"><span class="glyphicon glyphicon-home"></span> Sales</a></li> 
     </ul> 
     <ul class="nav navbar-nav navbar-right"> 
      <li><a href="#"><span class="fa fa-cogs"></span> Services</a></li> 
      <li><a href="#"><span class="glyphicon glyphicon-comment"></span> Contact</a></li> 
      <li><a href="#"><span class="glyphicon glyphicon-link"></span> About Us</a></li> 
     </ul> 
     </div> 
    </div> 
</nav> 
</header> 

在自定義CSS我有,但沒有任何反應它不會從白到黑的改變:

.active { 
    background-color: black !important; 
} 
+0

嘗試改變導航欄類.. [http://www.w3schools.com/bootstrap/tryit.asp ?filename = trybs_navbar_inverse&stacked = h] – SR1092

回答

5

只是改變了.active類的背景下將無法正常工作

嘗試以下操作:

ul.nav a:hover, ul.nav a:focus, ul.nav a:active { color: #000; } 

我不事!important將necessairy

+0

謝謝!這段代碼做了工作 ul.nav a:focus,ul.nav a:active {background-color:black; } –

+0

不客氣,請接受答案作爲正確答案,以便Stack上不存在不必要的開放問題。 – Peter