I’ve been playing with the CSS for a table, trying to affect cell fill background colors. I’ve gotten really close to what I need, but am stuck on one cell.
Top row and left column need to be red. Done. Right column needs to be blue. Done – except the top right cell is red from the 1st row CSS. That’s where the problem is.
How can I also get the top row last column cell to have the blue background without affecting the rest of the first row?
Thank you!
Here’s my CSS:
/* changes table's first row and column background colors */
.custom-table tr:first-child td{
background-color: #9e172d !important;
}
.custom-table td:first-child{
background-color: #9e172d !important;
}
.custom-table td:nth-child(4) {
background-color: #3870e2 !important;
}
2
Answers
This selector:
Has more specificity than this one:
One option could be to add another, more specific selector for your third rule (for the blue color) specifically for the case of the top-row element in that column. For example:
I’ll demonstrate using a simple code snippet: