Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Overriding bootstrap table-striped CSS

I am trying to change the background-color of rows that contain my found class in a striped bootstrap table. It works for even rows because bootstrap doesn't have a background color for them, but odd rows I am blocked by bootstraps CSS.

Bootstrap CSS:

.table-striped > tbody > tr:nth-child(odd) > td,
.table-striped > tbody > tr:nth-child(odd) > th {
  background-color: #f9f9f9;
}

Custom CSS:

 tr.found{
    background-color:#CECBCB;
}

How would I override bootstrap's CSS for only a single row at a time (as you can see in demo, odd rows are not overridden)?

BOOTPLY DEMO

like image 867
Jordan.J.D Avatar asked Jul 30 '14 17:07

Jordan.J.D


People also ask

What makes bootstrap striped table?

Use the combination of table and table-stripped classes within the <table> tag to create a striped table.

How do you change the color of a table in bootstrap?

Using pre-defined classes, we can change the color of table cells and table rows. In order to change the color of the table row, we need to specify in <tr> tag with the required class & for changing the color of the table row then specify it inside <td> tag with the required class.

What is table hover in Bootstrap?

Using the . table-hover class, a light gray background will be added to rows while the cursor hovers over them.


1 Answers

Write specific selector to override the bootstrap ones

table.table.table-striped tr.found td {
    background-color:#CECBCB;
}

Demo

Also, not only specificity matters here, make sure you apply the background to the td element and not the tr because bootstrap is applying to the td element so even if you apply the background to tr won't make sense.


As you said that you wanted the explanation for the selector I wrote, so here it goes, let us break that and understand..

Starting off with this

table.table.table-striped - Over here am selecting a table element having classes .table AS WELL AS .table-striped

Going further with the selector, tr.found we select the tr elements having a class called .found and lastly, we select the nested td elements.

like image 108
Mr. Alien Avatar answered Sep 29 '22 11:09

Mr. Alien