html - Adding a black background to bootstrapped fixed-top navbar


Keywords:html 


Question: 

I'm having a lot of trouble adding a fixed black background to my bootstrapped navbar. In my CSS, I declared the background-color as black, but it doesn't seem to change anything. My own CSS is declared after bootstrap's core CSS, so it wouldn't be overridden by a default color. The nav bar shows as transparent, with opaque lettering. Not sure what the problem is, especially since I already declared the color of the navbar!

Here is the HTML for the navbar:

<div class="jumbotron">
  <div class="container">
    <nav class="navbar fixed-top">
      <div class="navbar-fixed-top container">
        <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="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
        </div>
        <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
          <ul class="nav navbar-nav navbar-right">
            <li><a href="">Home</a></li>
            <li><a href="">About</a></li>
            <li>
              <a href="" role="button" aria-haspopup="true" aria-expanded="false">Personal Projects<span class="caret"></span></a>
            </li>
              <li><a href="">Bullet Blog</a></li>
            <li><a href="">Contact</a></li>
          </ul>
        </div>
      </div>
</nav

And here is my CSS. Please help. I am going insane.

.jumbotron navbar-fixed-top container{
    background: 2E2F31;
    position: fixed; 
    width: 100%;
}
.navbar .navbar-nav li a {
    color: white;
    font-size: 16px;
}
.navbar .navbar-nav li a:hover {
    background: BFC1C3;
}
.navbar .navbar-nav .dropdown-menu li a:hover {
    background: BFC1C3;
}

2 Answers: 

change your css from .jumbotron navbar-fixed-top container to .jumbotron .navbar-fixed-top.container I updated your code check here

.jumbotron .navbar-fixed-top.container{
    background: 2E2F31;
    position: fixed; 
    width: 100%;
}
.navbar .navbar-nav li a {
    color: white;
    font-size: 16px;
}
.navbar .navbar-nav li a:hover {
    background: BFC1C3;
}
.navbar .navbar-nav .dropdown-menu li a:hover {
    background: BFC1C3;
}
<html lang="en">
<head>
  <link rel="stylesheet" href="">
  <script src=""></script>
  <script src=""></script>
</head>
<body>

<div class="navbar-inverse jumbotron">
    <div class="container">
        <!-- Header -->
 <nav class="navbar fixed-top">
      <div class="navbar-fixed-top container">
        <div class="navbar-header">
           <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
        </div>
        <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
          <ul class="nav navbar-nav navbar-right">
            <li><a href="">Home</a></li>
            <li><a href="">About</a></li>
            <li>
              <a href="" role="button" aria-haspopup="true" aria-expanded="false">Personal Projects<span class="caret"></span></a>
            </li>
            <li><a href="">Bullet Blog</a></li>
            <li><a href="">Contact</a></li>
          </ul>
        </div>
      </div>
    </nav>
    </div>
</div>




</body>
</html>
 

I think this is exactly what you need

<head>
    <link rel="stylesheet" href="">
    <link rel="stylesheet" href="">
    <script src=""></script>
</head>

<body>

    <div class=" jumbotron">
        <div class="container">
            <!-- Header -->
            <nav class="navbar-fixed-top navbar-inverse">
                <div class="container">
                    <div class="navbar-header">
                        <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
                    </div>
                    <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                        <ul class="nav navbar-nav navbar-right">
                            <li class="active"><a href="">Home <span class="sr-only">(current)</span></a></li>>
                            <li><a href="">About</a></li>
                            <li>
                                <a href="" role="button" aria-haspopup="true" aria-expanded="false">Personal Projects<span class="caret"></span></a>
                            </li>
                            <li><a href="">Bullet Blog</a></li>
                            <li><a href="">Contact</a></li>
                        </ul>
                    </div>
                </div>
            </nav>
        </div>
    </div>
</body>

OPTIONAL--and if you want to change it even further with any other color use the following css:

.navbar-inverse {
    background-color: 122c46;
    border-color: 122c46;
}