使用bootstrap更改导航栏的字体颜色

时间:2017-12-30 17:45:52

标签: html css twitter-bootstrap fonts

我一直试图覆盖导航栏的字体颜色,但我似乎无法弄明白。我希望背景颜色为橙色,字体颜色为白色。

导航栏的HTML:

<nav class="navbar navbar-expand-lg navbar-light bg-light">
   <a class="navbar-brand" href="#">Rocalytics</a>
   <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent"
      aria-expanded="false" aria-label="Toggle navigation">
   <span class="navbar-toggler-icon"></span>
   </button>
   <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav mr-auto">
         <li class="nav-item active">
            <a class="nav-link" href="#">Value Proposition</a>
         </li>
         <li class="nav-item dropdown active">
            <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true"
               aria-expanded="false">
            Dropdown
            </a>
            <div class="dropdown-menu" aria-labelledby="navbarDropdown">
               <a class="dropdown-item" href="#">Scheduling</a>
               <div class="dropdown-divider"></div>
               <a class="dropdown-item" href="#">Contact Management</a>
               <div class="dropdown-divider"></div>
               <a class="dropdown-item" href="#">Analytics</a>
            </div>
         </li>
         <li class="nav-item active">
            <a class="nav-link" href="#">User Experience</a>
         </li>
         <li class="nav-item active">
            <a class="nav-link" href="#">Contact Us</a>
         </li>
      </ul>
      <form class="form-inline my-2 my-lg-0">
         <button class="btn btn-outline-success my-2 my-sm-0" type="submit">Sign Up</button>
      </form>
   </div>
</nav>

CSS:

/* NAVBAR */
.navbar {
  background-color: #f78c20 !important;
  color: white !important;
}

背景颜色设法改变,字体颜色不改变。我也试图避免使用!important。有什么建议吗?

1 个答案:

答案 0 :(得分:0)

您可以将类添加到更具体的标记,例如nav-linkdropdown-item

/* NAVBAR */

.navbar {
  background-color: #f78c20 !important;
  color: white;
}

.nav-link,
.dropdown-item {
  color: white;
}
<nav class="navbar navbar-expand-lg navbar-light bg-light">
  <a class="navbar-brand" href="#">Rocalytics</a>
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>

  <div class="collapse navbar-collapse" id="navbarSupportedContent">
    <ul class="navbar-nav mr-auto">
      <li class="nav-item active">
        <a class="nav-link" href="#">Value Proposition</a>
      </li>
      <li class="nav-item dropdown active">
        <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
            Dropdown
          </a>
        <div class="dropdown-menu" aria-labelledby="navbarDropdown">
          <a class="dropdown-item" href="#">Scheduling</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="#">Contact Management</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="#">Analytics</a>
        </div>
      </li>
      <li class="nav-item active">
        <a class="nav-link" href="#">User Experience</a>
      </li>
      <li class="nav-item active">
        <a class="nav-link" href="#">Contact Us</a>
      </li>

    </ul>
    <form class="form-inline my-2 my-lg-0">
      <button class="btn btn-outline-success my-2 my-sm-0" type="submit">Sign Up</button>
    </form>
  </div>
</nav>