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?

https://i.sstatic.net/mzJIo.png

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

UTF-8 encoding experiencing issues on select Android mobile devices

Our new website, powered by Wordpress, is up and running but some users are experiencing issues with displaying Swedish special characters. It seems to be happening specifically on Android devices, regardless of the browser being used. However, I have not ...

Creating a link button using JavaScript

I have integrated a Setmore code on my website to facilitate appointment booking, which triggers a popup similar to what you would see on a hotel reservation site. <script id="setmore_script" type="text/javascript" src="https://my.setmore.com/js/iframe ...

Issues with image sizing on mobile devices

After finalizing my header design, I encountered an issue with the mobile version of the website. The images in the header are not responsive and do not adapt well to different screen sizes. I need assistance converting the header design into functional co ...

Having trouble with implementing checkbox hack syntax

I'm trying to achieve a unique effect where a label gets styled and a div gets revealed when a checkbox is checked. Surprisingly, I've managed to make one happen without the other in my attempts. Even though the CSS is consistent in both instance ...

Displaying PHP output within a JavaScript expression

Let's dive into a scenario involving a basic HTML document and some JavaScript that's loaded within it: <!-- doc.html --> <!doctype html> <html lang="en"> <head> <script type="text/javascript" src=" ...

JQuery - stylish vertical accordion navigation menu

I'm currently working on a vertical accordion-style sidebar navigation system. Everything seems to be functioning properly, but I've encountered some issues with the icons that I'm using from Twitter Bootstrap 3. You can view the code on th ...

Incorporate an ASP table within an ASP table to enhance data organization and presentation

Is it possible to create a dynamic ASP.NET table structure similar to the one demonstrated below by nesting tables inside table cells? <table> <tr> <td>[Image]</td> <td> <table> <tr> ...

The SVG icon displays properly when viewed on a local machine, but is missing when the website is deployed

Something strange is happening with my SVG sprites. Everything seems to be working fine when I test my code locally, but once deployed on Firebase, one of the SVG images fails to appear. What could be causing this issue? Below is the code for two SVGs: sm ...

Localization for Timeago JS Plugin

Currently, I have integrated the jQuery TimeAgo plugin into my project and included the following code snippet for localization in Portuguese: // Portuguese jQuery.timeago.settings.strings = { suffixAgo: "atrás", suffixFromNow: "a partir de agora", ...

An always-visible navigation menu

After exploring various resources related to the same topic, such as sticky navigation bars and others, I noticed that all the solutions provided involved the use of this link http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js. However, inc ...

Adaptive Positioned Image Display

I currently have a Section with four blocks of content. Along the right-hand side of the screen, there are some images (as shown in this example) that I want to position absolutely. However, I am encountering an issue where these images overlap with the te ...

Tips for adjusting the width of an li element based on the width of its longest content

My database dynamically populates an unordered list with content, utilizing the following code in the back end: StringBuilder output = new StringBuilder(); int lastDepth = -1; int numUL = 0; foreach (DataRow row in dt.Rows) { ...

Designing Material UI Button Styles

Hello, I recently started using Material UI and I'm facing some challenges in styling the components. Right now, I'm working on a sign-in page and trying to position the Submit button all the way to the bottom right corner. Any help or advice wou ...

`In Firefox, perspective can lead to unexpected overflow errors.`

Having difficulties setting up a parallax effect using CSS perspective and translateZ. Encountering strange overflow errors specifically in Firefox. Check out the issue here When moving the mouse around, noticing that the background-image is getting crop ...

Stop material button from animating when clicked

On my webpage, I have created a unique button structure using Angular Material design: <button mat-button class="library-tile-button"> <button mat-button class="edit-library-button"> <img class="edit-library-img" src="..."/> ...

Ways to change specific CSS class properties in a unique style

As a Java programmer using primefaces 5.1, I've encountered some challenges with handling CSS classes. One particular issue I'm facing is the need to override certain CSS properties to remove the rounded corners of a DIV element. The rendered cod ...

Show a clear box over an HTML table row upon mouseover, without highlighting the row

I'm looking to implement a transparent box, with a button, that surrounds a table row when the user hovers over it. I've searched on Google but all the pages only talk about how to highlight rows on hover. I am currently using JavaScript to add ...

Adjust the size of the child div to fit the remaining space within the parent div

I'm dealing with a situation where there are two child divs inside a parent div. The first child div takes up 32% of the width, while the second child div takes up 68% of the width. If I were to set the display of the first child div to "none", how ca ...

Display a background color behind an <img> element when the image's dimensions are smaller than the page

Currently, I am utilizing the following CSS for styling an image - check it out here img { border: 3px solid #ddd; margin-left: auto; display: block; margin-right: auto; background: red; } If you would like to view the output, click on this link - see it ...

jQuery Issue - Clash between multiple menus sharing the same class

Hey there! I'm currently diving into the world of jQuery and encountering an issue with my menu. Whenever I click on a menu item with either the "tm-nav-vertical" or "tm-nav-horizontal" class, it removes the .active class from the initial menu item. I ...