Overriding bootstrap table-striped CSS

前端 未结 3 1870
一生所求
一生所求 2021-02-05 11:57

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

相关标签:
3条回答
  • 2021-02-05 12:20
    .table-striped>tbody>tr:nth-child(odd)>td,
    tr.found{
        background-color:#CECBCB;
    }
    
    0 讨论(0)
  • 2021-02-05 12:26

    In addition to Mr. Alien's solution, I found that the following works in Bootstrap 4 without explicitly overriding the table style.

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

    Bootply Demo

    0 讨论(0)
  • 2021-02-05 12:29

    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.

    0 讨论(0)
提交回复
热议问题