How to change the color of Bootstrap navbar links

Asked

Viewed 4,128 times

0

How can I change the color of the links present in the standard Bootstrap navbar? I can change the navbar backgroud colors by an external css file but not the link colors. How can I do?

Toggle navigation Brand

<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-expanded="false">Dropdown <span class="caret"></span></a>
      <ul class="dropdown-menu" role="menu">
        <li><a href="#">Action</a></li>
        <li><a href="#">Another action</a></li>
        <li><a href="#">Something else here</a></li>
        <li class="divider"></li>
        <li><a href="#">Separated link</a></li>
        <li class="divider"></li>
        <li><a href="#">One more separated link</a></li>
      </ul>
    </li>
  </ul>
  <form class="navbar-form navbar-left" role="search">
    <div class="form-group">
      <input class="form-control" placeholder="Search" type="text">
    </div>
    <button type="submit" class="btn btn-default">Submit</button>
  </form>
  <ul class="nav navbar-nav navbar-right">
    <li><a href="#">Link</a></li>
  </ul>
</div>

'

1 answer

0


You need to create your additional css style to be more specific in the element a, because bootstrap applies styles directly to the tag a. See the example below:

.navbar-nav > li >a{
  color: red;
}
.navbar-nav > li:hover >a,
.navbar-nav > li.active >a
{
  color: blueviolet;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">


  <ul class="nav navbar-nav">
    <li><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-expanded="false">Dropdown <span class="caret"></span></a>
      <ul class="dropdown-menu" role="menu">
        <li><a href="#">Action</a></li>
        <li><a href="#">Another action</a></li>
        <li><a href="#">Something else here</a></li>
        <li class="divider"></li>
        <li><a href="#">Separated link</a></li>
        <li class="divider"></li>
        <li><a href="#">One more separated link</a></li>
      </ul>
    </li>
  </ul>
  <form class="navbar-form navbar-left" role="search">
    <div class="form-group">
      <input class="form-control" placeholder="Search" type="text">
    </div>
    <button type="submit" class="btn btn-default">Submit</button>
  </form>
  <ul class="nav navbar-nav navbar-right">
    <li><a href="#">Link</a></li>
  </ul>

  • I updated the example. Check if you can make it work now.

  • Two questions: 1 - Pq can only apply the change by passing the full element path (.navbar-nav > li:hover >a) or through id? I tried to create a class of my own for these changes but it had no effect. There is a 3rd color effect that is applied when clicking on a dropdown menu it applies a shade similar to the color of the :active but it’s not, :active only works while the mouse is pressed, test the dropdown of the example da doc. You will see that it applies a color while Meno is open.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.