Marshawn Perkins
Marshawn Perkins

Reputation: 13

Selectors for Navbar text

What selectors do i need to call to change the text color on the navbar? I tried just calling on .navbar and had no change? I also tried calling .nav.navbar li and still no luck.

.bg-1 {
  background-color: black;
  color: yellow;
}

.nav.navbar-nav li {
  color: yellow;
}
  <header>
      <nav class="navbar navbar-default">
        <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="#">Honey Dos Salon</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="#">Home <span class="sr-only">(current)</span></a></li>
              <li><a href="#">Pricing</a></li>
              <li><a href="#">Contact</a></li>
            </ul>
          </div><!-- /.navbar-collapse -->
        </div><!-- /.container-fluid -->
      </nav>
  </header>

Upvotes: 1

Views: 244

Answers (3)

Renzo Gaspary
Renzo Gaspary

Reputation: 300

The anchor tag has it's own css properties that you need to specify in order to override.

.nav.navbar-nav li a {
  color: yellow;
}
<!-- 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 href="#">Pricing</a></li>
    <li><a href="#">Contact</a></li>
  </ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->

Upvotes: 0

A.Marques
A.Marques

Reputation: 131

You're doing it correctly, but the problem probably is you also having selectors changing the color of all "< a >" tags, or having more selective selectors:

nav{
 color: black;
}

nav.navbar-nav{
 color:yellow;
}
a{
 color: red
}

The first selector will be replaced by the second one because "nav.navbar-nav" is more selective than just "nav". But since the text is inside "< a >" tags, their color will be red.

There is however 2 ways to override those selectors:

1.Create a more selective selector:

nav.navbar-nav li a.color-yellow{
 color: yellow;
}

2.Use !important:

nav.navbar-nav{
 color: yellow !important;
}

!important properties will have higher priority over other properties.

Upvotes: 1

web developer
web developer

Reputation: 126

add the class to the anchor tag not for li. something like below to add color for text.

.nav.navbar-nav li a {
    color: red;
}

Upvotes: 0

Related Questions