1

I am trying to change the background color of my navbar, but it's not working. This is my html :

<html>
<head>
    <link rel="stylesheet"
href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="admin_header.css">
</head>

<body >


<nav class="navbar navbar-default">
  <div class="container-fluid">

    <ul class="nav navbar-nav">
  <li><a href="#"> <span class="glyphicon glyphicon-home"></span> Home page </a> </li>


  <li><a href="#"> <span class="glyphicon glyphicon-off"></span> Log out</a></li>
    </ul>
  </div>
</nav>
</body>
</html>

This is my css:

.nav.navbar-nav li a{
color: white !important;
}

    .navbar-default {
    background-color: #3232ff !important;
}

Before, my css file was like below and it worked:

.nav.navbar-nav li a{
color: #3232ff !important;
}

Now, there is something weird going on, because before i was using the same css file with styles for the anchor link color only. Now that I changed it and also added styles for the background color of navbar it doesn't work.The color remains the same as before I made the changes.

eli
  • 313
  • 3
  • 6
  • 17

3 Answers3

0

Try adding a class to your navbar, Bootstrap is overwriting your styles.

for example in your css you could do

.myNavbar.nav.navbar-nav li a {}

edit: In your html page you are creating, for example just add to <ul class="nav navbar"> this <ul class = "myNavbar nav navbar-nav" >

edit: here is a jsfiddle It seems that you don't really understand the important! flag https://jsfiddle.net/DTcHh/37347/

Quoting slebetman:

  • Never use !important on site-wide css.
  • Only use !important on page-specific css that overrides site-wide or foreign css (from ExtJs or YUI for example).
  • Never use !important when you're writing a plugin/mashup.
  • Always look for a way to use specificity before even considering !important
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Demon
  • 826
  • 7
  • 22
0

Use this Code

.navbar-nav li a {
            color: white ! important;
        }

        .navbar-default {
            background-color: #3232ff !important;
        }

This will solve your problem.

Aminur Rahman
  • 400
  • 1
  • 6
  • 14
0

  .navbar-nav li a {
            color: white !important;
        }

        .navbar-default {
            background-color: #3232ff !important;
        }
<!DOCTYPE html>
<html>
<head>
    <link rel="stylesheet"
          href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">


</head>

<body>


    <nav class="navbar navbar-default">
        <div class="container-fluid">

            <ul class="nav navbar-nav">
                <li><a href="#"> <span class="glyphicon glyphicon-home"></span> Home page </a> </li>


                <li><a href="#"> <span class="glyphicon glyphicon-off"></span> Log out</a></li>
            </ul>
        </div>
    </nav>
</body>
</html>
Aminur Rahman
  • 400
  • 1
  • 6
  • 14