HTML navigation bar background color

Currently, I am customizing a Bootstrap template and my objective is to modify the color scheme of the navigation bar located at the top.

The segment of code that pertains to this task is as follows:

<!-- Navigation -->
<nav class="navbar navbar-expand-lg navbar-light bg-light fixed-top">
  <div class="container">

    <a class="navbar-brand" href="#"><img src="https://home.channeliser.com/Content/WebContent/images/logo1.png" alt="Channeliser" height="40" width="100"></a>
    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
          <span class="navbar-toggler-icon"></span>
        </button>
    <div class="collapse navbar-collapse" id="navbarResponsive">
      <ul class="navbar-nav ml-auto">
        <li class="nav-item">
          <a class="nav-link" href="#">About us</a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#">How it works</a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#">Services</a>
        </li>
      </ul>
    </div>
  </div>
</nav>

In attempting to change the background color using the navbar class in the CSS file, my efforts were unsuccessful. Any guidance or assistance on this matter would be greatly appreciated.

Answer №1

.navbar {
    background-color: red;
}

It's difficult to determine if this code will work without considering the rest of the CSS on the page, but in isolation it appears to be sufficient.

Answer №2

Works perfectly with Bootstrap 4

Simply delete the bg-light class and add your own custom class instead

For example:

Your original code :

<nav class="navbar navbar-expand-lg navbar-light bg-light fixed-top">

</nav>

Change it to :

<nav class="navbar navbar-expand-lg navbar-light your-bg-navbar fixed-top">
   //navbar item
</nav>

Delete bg-light and apply your own CSS styles

Add this CSS :

.your-bg-navbar {
    background-color: rgba(35,35,35,0);
}

rgba is for transparency, you can use a solid color as well.

Set the background-color to red or #rgbcolor

Hoping this solution works out for you too!

Answer №3

The reason for this is that the .bg-light class has a background color set with an !important declaration, which means it will take precedence over any other styles unless you also use !important:

.navbar {
background: red !important;
}

Answer №4

Based on personal experience, Bootstrap CSS will typically override any custom CSS styles you apply unless you use the !important tag at the end of the property declaration. In this case, the solution to your query would be:

.navbar {
background-color: red !important;
}

Alternatively, you have the option to include a custom CSS file where you can replace the bg-light class with your own custom class.

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

Unexpected appearance of DOM elements

I've come across an unusual bug in a web application I've been developing that is reproducible in Chrome and Safari, but not in Firefox. To witness the bug, go to www.lastcalc.com and type a single uppercase letter. The letter will be immediatel ...

The backdrop refuses to be shown

Recently, I picked up a project from codepen.io and made some modifications to it. However, I am currently facing an issue while trying to add a background image that won't display on the screen. Below is the snippet of my code: body { background ...

After running assets:install and assetic:dump, Font Awesome fonts are no longer functioning properly

Setting up a site on shared hosting has been going smoothly, except for the FontAwesome icons which Symfony is having trouble finding in their designated locations. The steps I followed to move the site to production on shared hosting are: To overcome th ...

The input and label are not experiencing any overflow

I've been following a tutorial to create an animation on an input and label. I successfully did it once today in school, but for some reason, it's not working now. My objective is to have the label inside the "input" field, with the input taking ...

Exploring the implementation of if statements within jQuery UI Autocomplete

Can conditional statements be used in the response event and the render item implementation? I have two separate JSON files that are accessed through data attributes in #searchbox and .searchbar to retrieve URLs. Since the file objects are different, it se ...

Live search filter technology

I am in need of a real-time search filter for my user directory, which is structured in rows and columns. Although I have implemented a search filter using JavaScript or jQuery, it hides more information than I would like. Unfortunately, I lack proficienc ...

Tips on choosing the initial N website elements that match a specific CSS selector using Python Selenium

Currently, I am utilizing phantomJS in a python/selenium configuration to scrape the screen. My main objective is to extract the first N elements that match a specified CSS selector. An issue I am encountering is that there are significantly more matching ...

Unique content on a web page when it is loaded with HTML

Is there a way to dynamically load various content (such as <img> and <a>) into divs every time a page is loaded? I've seen websites with dynamic or rotating banners that display different content either at set intervals or when the page ...

Advantages of combining HTML and CSS elements in web development

I recently came across a CSS text in one of my Code Academy lessons that looked like this: html,body { font-family: 'Roboto', sans-serif; color: #404040; background-color: #eee; } Why are both "html" and "body" elements targeted in ...

Retrieve the selected value from a dropdown menu in HTML and PHP on the same

Seeking guidance on HTML select form. I have 5 select forms arranged as illustrated in the image below. https://i.sstatic.net/uNHHB.png The chosen value from the first select form determines the options displayed in the subsequent select form. These opt ...

Using JQuery to swap out background images in CSS

I have been working on a slider that is supposed to fade one picture over another. The issue is that the background change seems to only work in the Dreamweaver preview and not in the actual browser. loop = setInterval(function(){ $("#slider").css("ba ...

Error message: snapscroll plugin failing to activate

I'm having trouble implementing snapscroll on my website even though I followed the documentation. It specifically mentions that SnapScroll only works with containers set to 100% window height for single page sites. Here is the link to Snapscroll: Y ...

Interactive image popups with JavaScript

Seeking assistance in generating a popup when selecting an area on an image map using Javascript. As a novice in JS, I have successfully implemented popups for buttons before but encountered issues with this code within the image map - the popup appears br ...

Eliminate spacing between divs of varying heights

I'm facing an issue with my small gallery of images. Despite having the same width, they vary in height causing the second row to start below the tallest image from the previous row. How can I eliminate these empty spaces while still maintaining the v ...

Are none of the page links clickable?

Currently, I am in the process of creating a portfolio website. This is my first attempt at coding HTML and CSS from scratch without the aid of a layout template. I've encountered an issue that has me stumped - the links within the container are not ...

Could anyone kindly instruct me on how to eliminate or conceal this piece of JavaScript code?

I recently attempted to implement an event tracker on my website, but unfortunately, I made a mistake and now this unwanted script is displaying. How can I hide or remove it? I initially installed the script through Google Tag Manager, but even after remov ...

Align the last line of flex cells to the left side

I have created a flex structure that resembles a table and adjusts the number of cells based on the content. However, when the last row is not full, the remaining cells stretch to fill the empty space, which affects the overall appearance of the structure. ...

Optimal pixel dimensions for images in dynamic web design

My website, , has a masonry style layout where images are preloaded with infinite scroll. However, I noticed that the layout twitches when new images are loaded due to the lack of sizing on the images. To address this issue, I added width and height to the ...

php The header functionality is enabled, but there are errors present

After attempting to redirect to the index page upon logging in with an ajax button, I encountered a strange issue. Instead of being redirected to index.php, the header is not functioning properly and I simply receive the HTML code of index.php within my lo ...

While scrolling, the div moves behind the fixed content

There's an issue with the CSS property position:fixed that I need help with. On my jsfiddle, you'll notice that when you scroll and the black div reaches the top, it should become fixed in position by adding the "stick" style via JavaScript. Howe ...