0

I'm not well versed in CSS, but I understand the basic idea of specificity (or so I think). Recently I was trying to override the table CSS of Bootstrap 3, which was defined for each cell like so (this is a partial bit, the part that was effective on the inspected element):

.table > tbody > tr.danger > td, .table > tfoot > tr.danger > td { background-color: #ddd; } 

I was trying to override the background color of the entire row that contained that cell, with this:

table#results > tbody > tr.highlighted { background-color: #ffd15b; } 

Which, as I understand it, has higher specificity due to the ID. However it wasn't working at all, until I introduced the child td in my CSS:

table#results > tbody > tr.highlighted > td { background-color: #ffd15b; } 

Why didn't my first attempt work? I tried in both Safari and Chrome (latest versions)

2 Answers 2

2

Your problem is not CSS specificity, but merely the background of the cell ( <td> ) hiding the background of the row (<tr>) behind it.

Sign up to request clarification or add additional context in comments.

2 Comments

So in general does styling on child elements override (or hide) styling on parent elements?
@BrDaHa - "In general" doesn't apply here. The background of table cells has specific rules, described in 17.5.1 Table layers and transparency of the spec.
0

Try adding border-collapse property to the parent table like below
table#results { border-collapse: collapse;}

1 Comment

Yeah that doesn't work. I'm not sure this really addresses the question, and it's already applied from the bootstrap normalize.less file

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.