How to Stop Bootstrap's table-hover Class from Altering Cell Background Colors in a Table

I have a Django project where I am working on customizing the background color of priority cells in a table based on their status (high, medium, low). My table is styled using Bootstrap, which includes the table-hover class. However, when I hover over a row, the background color of the priority cells changes to the default hover color of the table instead of maintaining the custom colors I have set.

Below is the relevant HTML code:

<table class="table table-dark table-sortable table-hover">
    <thead>
        <tr>
            <th scope="col">Priority</th>
        </tr>
    </thead>
    <tbody id="table-body" class="table-body">
        <tr class="task-row">
            <td class="{% if task.priority == 'high' %}high-priority{% elif task.priority == 'medium' %}medium-priority{% else %}low-priority{% endif %}">
                {{ task.get_priority_display }}
            </td>
        </tr>
    </tbody>
</table>

And here is the CSS being used:

.table .high-priority {
background-color: hsl(5, 39%, 30%) !important;
}

.table .medium-priority {
background-color: hsl(27, 64%, 40%) !important;
}

.table .low-priority {
background-color: hsl(146, 34%, 25%) !important;
}

.table .task-row:hover .high-priority,
.table .task-row:hover .medium-priority,
.table .task-row:hover .low-priority {
background-color: inherit !important;
}

Issue:

Even with these styles in place, the background color of the priority cells continues to change when hovering over the row. I want the priority cells to retain their assigned colors regardless of hover state.

Question:

How can I prevent the background color of the priority cells from changing when hovering over the row, while still utilizing the Bootstrap table-hover class?

Screenshot displaying the issue while hovering over the table.

What I’ve Tried:

•   Using !important on the background colors.
•   Setting background-color: inherit for hover states of priority cells.

Answer №1

Get rid of

background-color: inherit !important;
, it's not going to give you the desired result.

The color issue you're facing is actually not from a background-color, but from a box-shadow that's being applied by

.table>:not(caption)>*>* {
    padding: .5rem .5rem;
    background-color: var(--bs-table-bg);
    border-bottom-width: 1px;
    box-shadow: inset 0 0 0 9999px var(--bs-table-accent-bg);
}

To fix this, replace it with box-shadow: none in your :hover rules instead of trying to inherit the background-color.

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

Saving drag and drop positions in Angular to the database and troubleshooting screen resizing problems

Currently, I'm working on an application that involves dragging and dropping a DIV onto an image. My goal is to save the X and Y coordinates of the dropped DIV to the database so that when the user returns, the position will remain the same. The chal ...

Populate a table dynamically in JavaScript using a variable

I have a table with IDs such as r0c1 = row 0 column 1. I attempted to populate it using the following script, but it doesn't seem to be functioning correctly: var data = new Array(); data[0] = new Array("999", "220", "440", "840", "1 300", "1 580", " ...

Best practices for integrating text and images within a website header using CSS and HTML

I need help figuring out the most efficient method for creating a page header that showcases an image while keeping the text visible for search engines and in case the image fails to load. According to Google, it is recommended to use a <div> for th ...

Showing database information from MySQL in a concealed div using PHP

My HTML code for the div is as follows: <div id="ticketupdates" style="display:none;"> </div> It then contains PHP code like this: <?php $sql2=" SELECT ticket_seq, CONCAT(CONCAT(notes),'<br><br><a hr ...

(Vue.js) The icon fails to be applied

<link rel="icon" href="/static/icons/apple-touch-icon.png" type="image/x-icon"> <link rel="icon" type="image/png" sizes="32x32" href="/static/icons/apple-touch-icon.png"> <link rel="icon" type="image/png" sizes="16x16" href="/static/ ...

Tips for optimizing a CSS file that includes the @page at-rule

When the CSS file for media='print' contains the @page directive, .myreceipt { @page { visibility: hidden; margin: 0 15px; } @page { height: auto; } } The ASP.NET MVC4 built-in minification tool does not ...

Strip the pound symbol from the end of a URL during an AJAX request

When I click on the News tab in my Rails application (version 2.3.4 and Ruby 1.8.7), an Ajax call is triggered to load data. <a href="News" onclick="load_feed();"><u>Show More...</u></a> <script> function load_feed() { $.a ...

Ensure that the width of the inner table matches the width of its contents within an overflowing div

I'm facing an issue with a table inside a div styled as table-wrapper: .table-wrapper { display: inline-block; overflow-x: scroll; width: 800px; } Although I want the div to display a horizontal scrollbar so that the table inside it can ...

Stroke on SVG Rect disappears suddenly without explanation

My rectangle seems to be losing some of its stroke randomly, sometimes after around 50 seconds. I can't figure out why this is happening, could you help me out? Here is the link to the fiddle - http://jsfiddle.net/nhe613kt/368/ Below is the relevant ...

How can we reduce the jitter experienced during page initialisation?

Is there a way to reduce the jittering effect on a page when using frameworks like jQuery/UI, especially with widgets like the button widget during layout processing on page load? I found setting the body tag to display: none, and then using $(function() ...

I am looking to use selenium to separate functions based on css selectors - how can this be achieved

I am attempting to modularize my script by breaking it down into various functions for easier reuse. However, when I do so, selenium seems to have trouble locating CSS selectors. Here is my folder structure: Startup.py Webdriver folder Contains init.p ...

Achieving Flexbox compatibility with child elements in a horizontal MUI Collapse Component and TransitionGroup transitions: A comprehensive guide

Struggling with incorporating the Collapse + TransitionGroup Component in MUI while trying to make the containers expand using flexbox. <Box sx={{display: 'flex', height: '100vh', width: '100vw'}}> <Box sx={{flex: 1 ...

Rotate font-awesome icons in a fixed position

I am interested in rotating my font-awesome icons by a static 45 degrees. The site mentions the following: To rotate and flip icons as desired, utilize the fa-rotate-* and fa-flip-* classes. However, when I try this: <i class="fa fa-link fa-rotate- ...

Experiencing an issue of receiving an undefined value while attempting to retrieve a value from an input box

HTML: <input value='Rename' type='button' onclick='RenameGlobalPhase({$row['id']});' <span id='renameGlobalPhase{$row['id']}'>" . $row['phase'] . "</span> Below you wil ...

Avoiding a mouse click event on an HTML element covered by a different HTML element

Utilizing the p5.js library in combination with reactJS, I have successfully created interactive visuals on my screen. Currently, when I click and drag my mouse on the screen, the background (or canvas) changes color thanks to p5.js. However, I am facing ...

How do you eliminate row highlighting on the <TableRow> component within Material-UI's <Table> using ReactJS?

I am facing an issue with a table and row highlighting in my code. Even after clicking on a row, it remains highlighted. I attempted to use the <TableRow disableTouchRipple={true}> but it didn't work as expected. What can I do to remove the high ...

What is the process for layering two images and positioning them at the bottom of a mobile screen?

I am encountering an issue with white space at the bottom of my mobile-responsive page. Specifically, I have two overlapping images within a div that I want to position at the bottom of the page, but I am unsure of the correct approach to eliminate this wh ...

Encountered an unexpected issue: Attempting to convert a circular structure to JSON. Can you identify the root cause of

There seems to be an error with the form submission: The form is not updating in the database. The following error is being displayed. const handleAddItem = (event) => { event.preventDefault(); const productName = productNameRef.current.value; ...

The code for the submit button functions properly in Firefox, but encounters issues in Internet Explorer

While this code functions correctly in Firefox, it fails to work in IE8. <a class="sub"> <input type="submit" a="" none;<="" display:=""> </a> Although the button appears on the page, it is not clickable in IE8. Can you help explain ...

Issue arises when implementing Ajax with a straightforward conditional statement

After spending hours on a seemingly small and trivial problem, I am feeling frustrated. I have been toiling away, trying different methods, rearranging variables, and experimenting with various approaches to solve it. The issue lies within the generateSpe ...