Enhancing a fixed-top navbar in Bootstrap with a sleek black background

I'm struggling to apply a solid black background to my bootstrapped navbar. Despite specifying the background-color in my CSS as black, the navbar remains transparent with opaque lettering. I've ensured that my custom CSS is declared after Bootstrap's core CSS, so it shouldn't be overridden by any default colors. Not sure what's causing the issue, especially since I've already defined the color for the navbar!

Here's the HTML code 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="#linktotop">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 code. Any help would be greatly appreciated.

.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;
}

Answer №1

Modify your CSS code from .jumbotron navbar-fixed-top container to

.jumbotron .navbar-fixed-top.container
. I have made the necessary updates, you can view them 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="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></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="#linktotop">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>

Answer №2

This could be just the solution you've been looking for

<head>
    <link rel="stylesheet" href="farji.css">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></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--If you want to further customize it with a different color, you can use this additional css:

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

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Combining SVG (Raphaël) and WebGL (THREE.js) for an innovative overlay

At the moment, I am utilizing the THREE.js library to showcase a 3D scene without any difficulties. My goal is to superimpose an SVG onto the scene, but I am encountering the following issue which can be best understood through the image provided: Withou ...

Concealing Contact Form Using Javascript

Upon making adjustments to a website, I encountered an issue with the contact form. The form is meant to be hidden on page load and only appear when the envelope icon is clicked. However, currently the form is visible by default, and clicking the envelope ...

Can columns in Bootstrap be used within a row without a container?

I am currently using bootstrap 4.6.0 and I have a question about the following code structure. While everything seems to be functioning correctly, I am uncertain if I should be utilizing a different container: <div class="container-fluid"> ...

The JavaScript link to reload an iframe is not functioning as expected

After creating a code snippet to refresh two iframes simultaneously upon clicking an image link, I found that it functions perfectly on the latest version of Google Chrome. However, it sadly does not seem to work on IE8... Check out the code below: <s ...

Tips for shifting a div to the left with AngularJS

I am working with a div structure that looks like the following: <div class="col-xs-1 scroll-button"><i class="glyphicon glyphicon-chevron-left"></i> </div> <div class="customer-ust-bant col-xs-22" id="letters"> <box n ...

Tips for maximizing page layout efficiency without compromising on element visibility

What is occurring https://i.stack.imgur.com/Agjw6.gif The use of .hide() and .fadeIn(200) is resulting in a jittery effect that I would like to avoid. Desired Outcome When the user hovers over the menu icon, the menu icon should vanish the text "Pr ...

Capturing the creation of dynamically generated text boxes using jQuery events

Is there a way for jQuery to detect when dynamically created DOM content is being added? Can this be achieved using jQuery? The webpage that I am working on generates text boxes dynamically, and I have no control over this process. However, I would like t ...

Unexpected behavior observed when applying position: fixed to navigation elements

Check out this JSFiddle I put together to showcase the structure of my webpage using HTML and CSS: http://jsfiddle.net/du7NN/ I've been working on a page that has a sticky navigation bar which stays at the top while the rest of the content scrolls. ...

Utilizing ID's within a jade template embedded within a P HTML element

Using the jade template, I successfully formed this paragraph. My next step is to add an ID or a class around the word stackoverflow. How can I achieve this in jade? I am aware that in regular HTML we would use something like <div class="className"> ...

Using the array `$_POST` by combining multiple pieces of data into a

Is it possible to receive arrays in $_POST without multiple hidden input fields and without using ajax to submit the form? Typically, I would set up the HTML like this: <input type="hidden" name="array[]" /> <input type="hidden" name="array[]" / ...

I encountered a problem with conflicting jquery ui tooltip and bootstrap.js. To resolve this issue, I tried implementing a new alias as recommended, but unfortunately, I am now receiving an

Adjusting Alias- : $.widget.bridge('uitooltip', $.ui.tooltip); Encountering an error when attempting to use jQuery tooltip with the new alias: Uncaught Error: cannot call methods on uitooltip prior to initialization; tried to call method & ...

javascript conceal a div when clicked elsewhere

I am trying to implement two JavaScript functions: 1) Displaying a DIV (welcomeDiv) when clicking on a button; 2) Hiding the div by clicking outside of 'welcomeDiv' container. function showDiv() { document.getElementById('welcomeDi ...

Consistent navigation bar across all pages created with JavaScript

There are various methods available to incorporate a navigation bar using either JS or JQuery, including utilizing the script tag in the page where it will be used. However, I find this approach less than optimal since once the script tag is utilized, JS ...

Can a partially see-through front color be placed on top of an image?

My goal is to add a foreground color with opacity over some images within a div, allowing the image to still be visible. I've come across solutions on S.O., like this one, but they don't quite achieve what I'm looking for. Below is my HTML ...

switch the anchor tag value and send it along with the URL

I am trying to update the value of "trans" in the Ajax URL based on a toggle between on and off values. However, despite successfully toggling the text, the URL parameter does not change accordingly. Can anyone offer any assistance? I currently have to rel ...

Strange behavior observed in Bootstrap navbar-brand class logo

As I work on creating a responsive HTML page using Bootstrap CSS, my focus is on the navbar-brand class that contains a logo element. Here's the code snippet in question: <div class="grad"> <a class="navbar-brand" id="navbar-logo" hre ...

Creating a visually appealing layout by positioning two images in opposite corners of a single div

As someone who's not well-versed in CSS, I could really use some assistance on creating a div with two images, similar to the diagram below. ...

The new data is not being fetched before *ngFor is updating

In the process of developing a "Meeting List" feature that allows users to create new meetings and join existing ones. My technology stack includes: FrontEnd: Angular API: Firebase Cloud Functions DB: Firebase realtime DB To display the list of meeting ...

Updating Template in Python Flask upon Button ClickLet's enhance our Python Flask application by

I need assistance with switching templates upon clicking a button. My Python code is as follows: @app.route("/", methods = ['POST', 'GET']) def my_forum_post(): if request.method == 'POST': if reque ...

What is the method to retrieve a string from a specific element in Selenium using Python?

I'm facing a challenge in extracting a specific string from the following HTML element: <textarea class="FormTextArea__textarea form-control" aria-label="Photo Caption" aria-describedby="photo-caption__help" id="photo-caption" rows="3">Exterior ...