Change navbar text color Bootstrap
Asked Answered
L

17

37

I currently have this piece of html which represents the relevant part of my navbar:

<nav class="navbar navbar-inverse" role="navigation">
    <div class="container">
        <ul class="nav navbar-nav navbar-right">
            <li><a href="#"><span class="glyphicon glyphicon-user"></span> About</a></li>
            <li><a href="#"><span class="glyphicon glyphicon-earphone"></span> Contact</a></li>
            <li><a href="#"><span class="glyphicon glyphicon-briefcase"></span> Portfolio</a></li>
            <li><a href="#"><span class="glyphicon glyphicon-list-alt"></span> R&eacute;sum&eacute;</a></li>
        </ul>
    </div>
</nav>

And I have this piece of css which I was hoping to use to change the text color of the navbar:

.nav.navbar-nav.navbar-right {
    color: blue;
}

The only problem is that the text color remains unchanged. I also saw that a very similar question went unsolved. I bet whoever can solve this one can solve the other too.

Leban answered 25/6, 2014 at 23:11 Comment(2)
You will probably have to target the li as well. Have you tried .nav.navbar-nav.navbar-right li a ? Or you could style each individual a tag with the font-color by giving it a class.Stickleback
Doing the " a" worked. If you post this as an answer, I will award you the question.Leban
S
44

Make it the following:

.nav.navbar-nav.navbar-right li a {
    color: blue;
}

The above will target the specific links, which is what you want, versus styling the entire list blue, which is what you were initially doing. Here is a JsFiddle.

The other way would be creating another class and implementing it like so:

HTML

<li><a href="#" class="color-me"><span class="glyphicon glyphicon-list-alt"></span> R&eacute;sum&eacute;</a></li>

CSS

.color-me{
    color:blue;
}

Also demonstrated in this JsFiddle

Stickleback answered 25/6, 2014 at 23:14 Comment(2)
Is there any way to make the toggle button blue too?Aric
This no longer works in bootstrap 5.xLump
A
22

As of bootstrap 4, the answer is to simply set navbar-dark in the nav element, which will set the text and links to a light theme .

<nav class="navbar navbar-dark">
Adolescence answered 26/5, 2018 at 13:22 Comment(1)
I don't know why this is not rated higher.Washerman
L
16
    .nav-link {
       color: blue !important;
    }

 /* Worked for me. Bootstrap v4.3.1 */
Layette answered 19/3, 2019 at 0:1 Comment(0)
M
9

For changing the text color in navbar you can use inline css as;

<a style="color: #3c6afc" href="#">
Morion answered 30/7, 2019 at 9:34 Comment(1)
For some reason none of the other solutions worked for me. Only this one did. ThanksCoffer
H
2

The thread you linked to does answer the question for you. You need to target the a elements themselves. E.g.

.nav.navbar-nav.navbar-right a {
    color: blue;
}

If that doesn't work, it just needs to be more specific. E.g.

.nav.navbar-nav.navbar-right li a {
    color: blue;
}
Heliochrome answered 25/6, 2014 at 23:17 Comment(0)
F
2

In fact, we can simply use the standard bootstrap text colors, instead of hacking the CSS formats.

Standard Color examples: text-primary, text-secondary, text-success, text-danger, text-warning, text-info

In the Navbar code sample bellow, the text Homepage would be in the orange color (text-warning).

<a class="navbar-brand text-warning" href="/" > Homepage </a>

In the Navbar menu item sample bellow, the text Menu Item would be in the blue color (text-primary).

<a class="dropdown-item text-primary" href="/my-link">Menu Item</a>
Fitton answered 8/6, 2019 at 5:50 Comment(0)
T
2

Just Add navbar-dark class in the <nav> tag like this

<nav class="navbar navbar-inverse navbar-dark">
Threaten answered 26/5, 2022 at 5:17 Comment(0)
R
1

Try this

.nav.navbar-nav.navbar-right li a span{
    color: blue;
}

If it doesn't work try this

.nav.navbar-nav.navbar-right li a {
    color: blue;
}
Reeves answered 25/6, 2014 at 23:17 Comment(0)
D
1

this code will work ,

.navbar .navbar-nav > li .navbar-item ,
.navbar .navbar-brand{
                       color: red;
                      }

paste in your css and run if you have a element below

  • define it as .navbar-item class

    eg .

    <li>@Html.ActionLink("Login", "Login", "Home", new { area = "" },
     new { @class = "navbar-item" })</li>
    

    OR

    <li> <button class="navbar-item">hi</button></li>
    
  • Dextrose answered 16/2, 2019 at 7:55 Comment(0)
    L
    0

    Try this in your css:

    #ntext{
     color: #000000;
      }
    

    Then the following in all your navigation bar list codes:

    <li><a href="#" id="ntext"><span class="glyphicon glyphicon-user"></span> About</a></li>
    
    Lynnell answered 3/8, 2016 at 8:55 Comment(0)
    H
    0

    If you need to change the background colour of the navbar, you can do the following:

    <nav class="navbar navbar-expand-lg navbar-light" style="background-color=#e3f2fd">
    

    And to change the text:

    <a class="nav-link" href="#" style="color:#ccc">
    
    Hoeve answered 2/11, 2018 at 12:32 Comment(1)
    OP has asked for the text color of the link, not the background colorMaintop
    A
    0

    Thanks WChoward for your answer. I expanded:

    .nav-link, .dropdown-item {
        color: blue !important;
    }
    .nav-link:hover, .dropdown-item:hover {
        color: darkgreen !important;
    }
    
    Aric answered 26/2, 2020 at 0:4 Comment(0)
    K
    0

    Add some inline css to the anchor tag

    <li><a style = "color:blue" href="#"><span class="glyphicon glyphicon-user"></span> About</a></li>
    

    This should add the color blue to the anchor tag text.

    Krefetz answered 30/12, 2020 at 15:13 Comment(0)
    S
    0

    Simple just do

    li a {
        color: blue;
    }
    
    Summerville answered 15/7, 2021 at 18:36 Comment(1)
    Welcome to StackOverflow. While this code may answer the question, providing additional context regarding how and/or why it solves the problem would improve the answer's long-term value. Furthermore please explain why your answer is preferable to the others.Marvamarve
    J
    0

    In Bootstrap 5.2.3 the following works:

    a.nav-link{
      color: blue;
    }
    
    <ul class="navbar-nav mb-2 mb-lg-0 ms-auto">
      <li class="nav-item">
        <a class="nav-link active" aria-current="page" href="#">Home</a>
      </li>
      <li class="nav-item">
        <a class="nav-link" href="#">About Us</a>
      </li>
      <li class="nav-item">
        <a class="nav-link" href="#">Contact Us</a>
      </li>
    </ul>
    
    Jacquenette answered 13/2, 2023 at 21:24 Comment(0)
    O
    0

    Inside your class-wp-bootstrap-navwalker.php file add style or class

    if ( false !== strpos( $args->items_wrap, 'itemscope' ) && false === $this->has_schema ) {
      $this->has_schema  = true;
      $args->link_before = '<span style="color:black" itemprop="name">' . $args->link_before;
      $args->link_after .= '</span>';
    }
    
    Oarfish answered 12/5 at 9:6 Comment(0)
    S
    -2

    The syntax is :

    .nav navbar-nav .navbar-right > li > a {
       color: blue;
    }
    
    Soyuz answered 21/8, 2017 at 14:55 Comment(0)

    © 2022 - 2024 — McMap. All rights reserved.