Is the background color not being implemented?

I'm struggling with an issue - I can't seem to apply a background color to my top bar. I've tried multiple times but it's still not working. Could you please help me fix this error?

Below is the code for my simple top bar:

topbar.html

<div class="header-top bg-dark" style="background-color: black;">
        <div class="container-fluid bg-dark" style="background-color: black;">
            <div class="left-side float-left ml-5">
                <p>Search</p>
                <p style="text-indent: 20px;">About Us</p>
                <p style="text-indent: 20px;">Contact Us</p>
            </div>
            <div class="right-side float-right mr-5">
                <p>Login</p>
                <p style="text-indent: 20px;">Register</p>
            </div>
        </div>
    </div>

Answer №1

There are a couple of issues you need to address:

  1. The float property is causing layout disruptions, so adding the .clearfix class to the parent element should resolve this.

  2. The bg-dark class uses !important, which means to override it you will have to use

    background-color: black !important;

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">

<div class="header-top bg-dark" style="background-color: black !important;">
  <div class="container-fluid bg-dark clearfix" style="background-color: black !important;">
    <div class="left-side float-left ml-5">
      <p>Search</p>
      <p style="text-indent: 20px;">About Us</p>
      <p style="text-indent: 20px;">Contact Us</p>
    </div>
    <div class="right-side float-right mr-5">
      <p>Login</p>
      <p style="text-indent: 20px;">Register</p>
    </div>
  </div>
</div>

Answer №2

It seems that by utilizing inline CSS, you have the option to create a separate file specifically for your CSS styles. You can then link this CSS file to your HTML document to keep your code organized and structured.

A simple example of defining a style in a separate CSS file could look like this:

.mycolor{ background-color: black;}

Answer №3

The reason you are seeing a different color is because of the class bg-dark being used in your code. To fix this, you can either remove the bg-dark class from the div or replace your code with the following lines:

<div class="header-top bg-dark" style="background-color: black !important;">
  <div class="container-fluid bg-dark clearfix" style="background-color: black !important;">

OR

<div class="header-top" style="background-color: black;">
  <div class="container-fluid clearfix" style="background-color: black;">

The use of !important will override the bg-dark class attribute in the div.

Answer №4

To avoid using inline styles for repeated elements like paragraphs, you can utilize the <styles> tag to keep your code more organized. Another option is to store your styles in a separate file and link it to your HTML document.

If your styles are not being applied, try using the !important declaration at the end of the style rule. Additionally, consider changing the text color to make it stand out.

Check out this example:

<div class="header-top bg-dark">
<div class="container-fluid bg-dark clearfix">
  <div class="left-side float-left ml-5">
    <p>Search</p>
    <p>About Us</p>
    <p>Contact Us</p>
  </div>
  <div class="right-side float-right mr-5">
    <p>Login</p>
    <p>Register</p>
  </div>
</div>
<style>
  .header-top, .container-fluid {
      background-color: black !important;
  }
  p {
      text-indent: 20px;
      color: white;
  }
</style>

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

When a cursor hovers over an image, a dark line appears

I wanted to create a hover effect where the image would enlarge when hovered over. I achieved this using a JavaScript function that applies the transform property with a scale of 1.2 to the picture. However, during the animation, a black line appears at th ...

Unusual problem encountered with Chart.js bar chart, image dispersion

On my HTML page, I have integrated a stacked bar chart using the Chart.js library to visually represent data for users. The data changes based on user selection, and the JavaScript function that enables this onclick feature is: function aggLav(){ [... ...

The container is not adjusting to the screen size correctly and the flex-direction: row is not functioning as

Struggling with setting up a basic layout in Angular for my application. While I have experience with Angular, the actual HTML/CSS design is new to me. No matter what I try, I can't seem to get this container to take up the whole screen width. Variou ...

The CSS file is not connecting properly despite being located within the same directory

I have double-checked that both of these files have the correct names and are in the exact same directory. However, for some mysterious reason, the CSS is not applying any styling to my page. I would greatly appreciate any assistance with this issue! Belo ...

Changing a background image url using jQuery by clicking a button

I'm struggling to find a way to use jQuery to add a background image URL to my CSS. Everything I've attempted so far has been unsuccessful. let button = document.querySelector('form button.btn') button.addEventListener('click&ap ...

Unable to match the height of the inner card image in bootstrap with the height of the outer card image

I'm facing an issue with two bootstrap cards, one nested inside the other, both containing images. Check out the StackBlitz here The inner image doesn't flex to the same height as the outer one, resulting in a small space between the two cards ...

Challenger arises in the realm of Chakra UI styling

Recently, I've encountered an issue with displaying a card using chakra UI and next js. The CSS of chakra UI seems to be messed up, causing all my components to display incorrectly. It was working perfectly fine until yesterday. I tried deleting the . ...

Implementing jQuery form validation including checking for the strength of the password

My understanding of jQuery was quite basic until I began working on jQuery form validation with password strength check. I successfully completed the password strength check portion, but now I am unsure of how to enable the submit button once the condition ...

Update the class name of an element depending on the URL

Hey there! I'm working on customizing the style of some elements (specifically tds within a table) based on the current URL. Here are the pages I'm targeting: http:\\domain\site\welcome.html http:\\domain\site& ...

Images for navigating forward and backward in a jQuery datepicker

I'm experimenting with setting custom images for the previous and next month buttons. I attempted to utilize the prevText / nextText options of the datepicker in order to include a span with my own CSS class definition. However, this resulted in the c ...

Is there a method to pre-load a CSS background image so that it can still be displayed even without an internet connection?

Situation: Imagine having a web app that shows an error message when trying to perform an action but fails due to a connectivity problem. The error dialogue has a CSS class with a background image that can't load because of the connection issue, res ...

JavaScript math validations not functioning correctly

This new project I've been working on involves presenting a multiplication problem and notifying the user if their answer is correct through an alert. The issue arises when the program incorrectly verifies the answers. Take a look at the code: < ...

Chrome is not storing the CSS file in its cache memory. However, it is successfully caching .js and .png

I have noticed that the CSS file is not being cached in the Chrome browser. My application is created using Angular-CLI and all the necessary cache-control headers are set, with an Expires header of 5 minutes: Accept-Ranges:bytes Cache-Control:max-age=600 ...

Revamping the Bootstrap framework in a major project

Currently, I am undertaking a project that involves the use of bootstrap 2.3.2 stylesheets along with bootstrap 3.0.0 .js scripts. The client side technology is significantly outdated and my primary objective is to update the bootstrap files to leverage th ...

Creating visually appealing tables with nested tables using CSS for styling including borders and backgrounds

Looking to create webpages that have a variety of tables, including a main table with a header (marked 2 on the picture) and several data tables for the user (marked 1 on the picture). To style these specific data tables, I've added some custom CSS: . ...

Issue with Laravel breadcrumbs not selecting the correct view

I'm currently utilizing the Laravel Breadcrumbs package from here: https://github.com/davejamesmiller/laravel-breadcrumbs Following all the provided instructions, I have successfully generated breadcrumbs. However, it seems that the package is not re ...

Issue in Firefox: Footer is wrapping around the main content

Hey, I've been dealing with a pesky bug that just won't go away. We're currently working on a redesign for www.petpoint.com - The footer looks perfectly fine in every browser except for Firefox. It gets all jumbled up for some reason. I&a ...

jQuery navigation is experiencing issues due to conflicting buttons

I am currently developing a web application that features two buttons in the header: Share and Options. When a button is clicked, its related content expands and collapses when clicked again. The issue arises when the user clicks on the share button and th ...

Typekit compatibility with Internet Explorer 11

After dedicating months to a project, everything seemed to be running smoothly until one client consistently pointed out font discrepancies in the screenshots. I attributed this to a possible browser issue but soon discovered that the entire network had sp ...

Update picture using Vanilla Javascript for mobile display

I am looking to change my logo color to white when viewed on mobile devices. Currently, I have the following code for changing the logo on scroll using vanilla JavaScript. The code toggles between a dark and light logo based on the scroll position. Howev ...