Bootstrap 5.3 does not allow custom background colors to take precedence

Ever since the update to Bootstrap 5.3.1, I've been facing an issue where two custom background colors are not overriding the colors set by Bootstrap, even when using !important. Strangely enough, they were working fine before the update.

Here are my styles:

table tr.shaded {
    background-color:#e1e9ff !important;
}
table tr.highlight {
    background-color:#eaeaf0 !important;
    font-weight: bold;
}

In Bootstrap 5.3.1 (tables.scss:5), the code snippet is as follows:

.table {
    ...
    --bs-table-bg: var(--bs-body-bg);
    ...
}

I have made sure that my CSS file is loaded after the Bootstrap file. Interestingly, if I disable the property mentioned above in Firefox's inspector, my custom background color shows up just fine.

I have gone through other threads discussing similar issues and can confirm that there are no typos in my CSS. It was functioning perfectly prior to the update, even without the use of !important. Additionally, all Bootstrap files are being loaded locally, and the entire website is accessible only on localhost - if that information is relevant.

I have tested this in both Firefox and Chrome, performing a full reload each time (Ctrl+Shift+R).

Any suggestions on how to resolve this?

EDIT: Adding the HTML code for reference.

<div class="col-lg-10 col-sm-12 table-responsive">
    <table class="table table-hover table-sm table-borderless list">
        <thead>
            <tr class="shaded text-center align-middle">
                <th width="25">ID</th>
                <th>Project name</th>
                <th>Languages</th>
                <th>Client</th>
                <th>Completed</th>
                <th><strong>Profit</strong></th>
                <th>Paid?</th>
                <th>Invoice</th>
            </tr>
        </thead>
        <tbody></tbody>
    </table>
</div>

Answer №1

When styling table elements in Bootstrap, the background color is set using the selector

.table > :not(caption) > * > *
. Your selector table tr.shaded is not specific enough to override Bootstrap’s style, even with the use of !important.

If you want to achieve the desired effect, try applying the background color to the th element instead of the tr element.

tr.shaded th {
    background-color:#e1e9ff;
}
tr.highlight th {
    background-color:#eaeaf0;
    font-weight: bold;
}
<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a0c2cfcfd4d3d4d2c1d0e0958e938e91">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet"/>
<div class="col-lg-10 col-sm-12 table-responsive">
    <table class="table table-hover table-sm table-borderless list">
        <thead>
            <tr class="shaded text-center align-middle">
                <th width="25">ID</th>
                <th>Project name</th>
                <th>Languages</th>
                <th>Client</th>
                <th>Completed</th>
                <th><strong>Profit</strong></th>
                <th>Paid?</th>
                <th>Invoice</th>
            </tr>
            <tr class="highlight text-center align-middle">
                <th width="25">ID</th>
                <th>Project name</th>
                <th>Languages</th>
                <th>Client</th>
                <th>Completed</th>
                <th><strong>Profit</strong></th>
                <th>Paid?</th>
                <th>Invoice</th>
            </tr>
        </thead>
        <tbody></tbody>
    </table>
</div>
<script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="99fbf6f6edeaedebf8e9d9acb7aab7a8">[email protected]</a>/dist/js/bootstrap.bundle.min.js"></script>

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

Options for regular expressions in CSS: match letters regardless of case and search for all occurrences

Here is the HTML I am working with: <div> <img class="hi" src="http://i.imgur.com/f9WGFLj.png"></img> <img class="HI" src="http://i.imgur.com/f9WGFLj.png"></img> </div> Additionally, I have the following CSS co ...

I'm having trouble grasping the concept of serving gzip-compressed JavaScript and CSS files

Why is it important to serve compressed JavaScript and CSS files? I understand that it reduces file size, but does the browser/webserver have to decompress them to read them? It's been mentioned that the webserver handles the compression. Does this me ...

Tips for maintaining a stationary element with fluctuating height positioned at the bottom in React

I am trying to create a fixed element with dynamic height, meaning its size changes when the browser window is resized. You can see an example of what I'm talking about here: https://stackblitz.com/edit/react-yuqarh?file=demo.tsx This element acts li ...

What is the best way to target outer elements only using CSS selectors?

Having trouble with a CSS selector: $("td.cv-table-panel-element") This selector returns a list of elements, shown in the screenshot linked below: https://i.stack.imgur.com/RoVMj.png Each element represents a column in a table with unique content. The ...

Preventing the image from being displayed when it cannot fully show is achieved through blocking the background repeat

Is there a way in CSS to only display a background image if it can be fully shown without setting the width in pixels? I want to avoid showing partial background images. Is there a CSS property that can help with this? [] <div align="left" style="pad ...

Align three divs vertically within one div, all floated to achieve the desired layout

Can someone help me align three divs vertically within a container div? The challenge is that all three divs inside the container are floated - one on the right, one in the center, and one on the left to create a navbar. I've seen the navbars in Boot ...

Bootstrap 5 introduces a new feature where col-sm-6 will take precedence over col-md

When using Bootstrap 5, I encountered an issue where the columns were not sizing evenly in a row. Specifically, on small screens, I wanted them to be exactly size 6. In this case, the columns should have been size 3 for screens larger than md, but they end ...

What is the best way to eliminate the space between columns?

I have a simple structure on BootStrap. <div class="container"> <div class="row"> <div class="col-md-4 blue-section" ><p>Some content</p></div> <div class="col-md-4 red-section"><p>Some content&l ...

Identify certain lines from the paragraph text

Suppose you have an HTML Paragraph Element (e.g., <p>) with certain text sections highlighted using a HTML Mark Element (e.g., <mark>). I am interested in adding a vertical line in the margin or gutter (uncertain about the appropriate term) tha ...

Having several horizontal scrollbars at once on a single webpage

I stumbled upon a great example showcasing how to scroll a div on my page: Check out this Codepen - https://codepen.io/zheisey/pen/xxGbEOx Although, I am looking to extend this functionality to allow multiple divs to scroll together. Any suggestions? I ...

I am having trouble getting the (:active) pseudo-class to function properly with the menu on my WordPress theme

Purchased a theme called HelpGuru and encountering issues with the CSS of the menu. Reached out to support but they were unable to assist, directing me to a company that specializes in customizing WordPress themes instead. The link to the demo can be found ...

Obtain the following image with every click

I have a div with images inside. I created two arrows (previous, next) within a larger div using the src of one of the images as the background URL for each arrow. My goal is to make the next arrow change the large image to the src of the following image w ...

The Infinite Loop: Unveiling the En

I'm interested in creating a unique shape resembling the symbol of infinity using CSS, SVG, or Canvas. If you're unfamiliar with what an infinity symbol looks like, here's an example: https://i.stack.imgur.com/cLhBh.jpg So far, I've a ...

The transparent overlay div does not activate when clicking on a button in Internet Explorer 10

While tidying up my CSS and JavaScript, I may have gone a bit overboard. The code seems to work fine on Chrome, Safari, and Firefox, but it's causing chaos in IE10. Check out the code here <div id="bgmbutton1"> <img id="button1" src ...

Having trouble getting the CSS class to work in MVC4 with jQuery implementation

I recently created a view page where I implemented some jQuery code: <script type="text/javascript"> $(document).ready(function () { var hdrname = $('#headername').text(); alert(hdrname); if (hdrname == "Pending Assignment") { ...

I'm struggling to concentrate and unable to type in the email field

Today while working on a website, I encountered something strange. In the footer section of the site, there is a quick contact form. However, I noticed that in Firefox, I am unable to focus on the email field. Surprisingly, this issue does not occur in Chr ...

Using CSS margins for elements lacking specific widths

Is there a way to centrally align a div element that doesn't have a set width? <html> <head> <title></title> <style type="text/css"> .outer { padding: 10px; /*margin: auto; (doesn´t work)*/ ...

Step-by-step guide on creating a draggable navigation bar:

I am encountering an issue creating a droppable menu. I am currently working on Menu 1 but struggling to figure out how to make the drop-down menus appear on the right side. <link href='http://fonts.googleapis.com/css?family=Oswald:300,400' r ...

Unicef's animated web content

Looking to learn more about gate animation and zoom page transition on the Unicef website? I want to incorporate these cool animations into my own project. Can someone provide me with a "keyword" or point me in the right direction to find information on ...

Unable to create a flawless circle using Canvas

No matter how hard I try, drawing a perfect circle seems impossible for me. Every time I attempt it, all I manage to create is an ellipse. Check out this code snippet I put together as an example: function canvasClicked(number) { var c = "canvas" + nu ...