如何更改引导程序导航菜单颜色?

时间:2015-09-22 01:22:55

标签: html css twitter-bootstrap

enter image description here

我想改变" Home"的颜色。 "旋" "社交媒体"但不知道如何。我花了几天时间来弄清楚如何更改导航背景但是没有关于颜色的线索,因为我只想将灰色更改为白色并改变悬停颜色。我可以将颜色更改为白色,但忽略悬停颜色。是否有预期的方法来做到这一点?

以下是我更改导航背景颜色的方法。

.navbar-inverse {
    background-color:#66ccff;
    background-image: none;
    background-repeat: no-repeat;
}

这有助于:D

3 个答案:

答案 0 :(得分:3)

这是导航组件的相对全面的细分,并且经常更改属性。我建议在主导航栏div中使用自定义类(本例中使用navbar-custom)以避免直接更改基本CSS。



/***Navbar Background Color, Border Removed ,Border Radius Sqaure***/

.navbar.navbar-custom {
  background: #66ccff;
  border: none;
  border-radius: 0;
}
/***Link Color***/

.navbar.navbar-custom .navbar-nav > li > a {
  color: #f00;
}
/***Link Color Hover Statr***/

.navbar.navbar-custom .navbar-nav > li > a:hover {
  color: #ff0;
}
/***Link Background and Color Active State***/

.navbar.navbar-custom .navbar-nav > .active,
.navbar.navbar-custom .navbar-nav > .active > a,
.navbar.navbar-custom .navbar-nav > .active > a:hover,
.navbar.navbar-custom .navbar-nav > .active > a:focus {
  background: #DBF022;
  color: #66ccff;
}
/***Navbar Brand Link Color***/

.navbar.navbar-custom .navbar-brand {
  color: #f00;
}
/***Navbar Brand Link Color Hover State***/

.navbar.navbar-custom .navbar-brand:hover {
  color: #ff0;
}
/***Dropdown Background Active State***/

.navbar.navbar-custom .nav li.dropdown.open > .dropdown-toggle,
.navbar.navbar-custom .nav li.dropdown.active > .dropdown-toggle,
.navbar.navbar-custom .nav li.dropdown.open.active > .dropdown-toggle {
  background: #DBF022;
  color: #f00;
}
/***Dropdown-menu Background Color***/

.navbar.navbar-custom .dropdown-menu {
  background: #66ccff;
  border: none;
}
/***Dropdown-menu Color***/

.navbar.navbar-custom .dropdown-menu > li > a {
  color: #f00;
}
/***Dropdown-menu Color Hover and Focus State***/

.navbar.navbar-custom .dropdown-menu > li > a:hover,
.navbar.navbar-custom .dropdown-menu > li > a:focus {
  color: #ff0;
  background: #f00;
}
/***Toggle Button***/

.navbar.navbar-custom .navbar-header .navbar-toggle {
  border-color: #f00;
}
/***Toggle Button Hover and Focus State***/

.navbar.navbar-custom .navbar-header .navbar-toggle:hover,
.navbar.navbar-custom .navbar-header .navbar-toggle:focus {
  background: #f00;
  border: #f00;
}
/***Collapse Borders***/

.navbar.navbar-custom .navbar-collapse {
  border: none;
}
@media (max-width: 767px) {
  .navbar.navbar-custom li.dropdown .dropdown-menu > li > a {
    color: #f00;
  }
  /***Dropdown-menu Color Hover and Focus State***/
  .navbar.navbar-custom li.dropdown .dropdown-menu > li > a:hover,
  .navbar.navbar-custom li.dropdown .dropdown-menu > li > a:focus {
    color: #ff0;
    background: #f00;
  }
}

<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-inverse 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-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> <a class="navbar-brand" href="#">Brand</a>

    </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="#">Link <span class="sr-only">(current)</span></a>

        </li>
        <li><a href="#">Link</a>

        </li>
        <li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>

          <ul class="dropdown-menu">
            <li><a href="#">Action</a>

            </li>
            <li><a href="#">Another action</a>

            </li>
            <li><a href="#">Something else here</a>

            </li>
          </ul>
        </li>
      </ul>
    </div>
    <!-- /.navbar-collapse -->
  </div>
  <!-- /.container-fluid -->
</nav>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

.navbar .nav > li > a 

这是你正在寻找的目标!

答案 2 :(得分:0)

自定义使用以下选择器...

(请注意,如果您的自定义设置是在bootstrap css之后加载的,那么您将不会需要!important,即<link href="..my-customizations.css" />之后加载<link href="...cdn...bootstrap.min.css" />

/* links */
.navbar-inverse .navbar-nav>li>a {
  color: red!important;
}

/* active, focus or hover links */
.navbar-inverse .navbar-nav>.active>a, 
.navbar-inverse .navbar-nav>.active>a:focus, 
.navbar-inverse .navbar-nav>.active>a:hover {
  color: red!important;
}

jsfiddle example