Bootstrap table striped: How do I change the stripe background colour?

后端 未结 12 1250
温柔的废话
温柔的废话 2020-12-01 02:21

With Bootstrap class table-striped, every other row in my table has a background colour equal to #F9F9F9. How can I change this colour?

相关标签:
12条回答
  • 2020-12-01 03:00
    .table-striped>tbody>tr:nth-child(odd)>td,
    .table-striped>tbody>tr:nth-child(odd)>th {
      background-color: #e08283;
      color: white;
    }
    .table-striped>tbody>tr:nth-child(even)>td,
    .table-striped>tbody>tr:nth-child(even)>th {
      background-color: #ECEFF1;
      color: white;
    }
    

    Use 'even' for change colour of even rows and use 'odd' for change colour of odd rows.

    0 讨论(0)
  • 2020-12-01 03:01

    If you want to actually reverse the colors, you should add a rule that makes the "odd" rows white as well as making the "even" rows whatever color you want.

    0 讨论(0)
  • 2020-12-01 03:04

    Don't customize your bootstrap CSS by directly editing bootstrap CSS file.Instead, I suggest to copy paste bootstrap CSS and save them in a different CSS folder and there you can customize or edit stylings suitable to your needs.

    0 讨论(0)
  • 2020-12-01 03:12

    With Bootstrap 4, the responsible css configuration in bootstrap.css for .table-striped is:

    .table-striped tbody tr:nth-of-type(odd) {
      background-color: rgba(0, 0, 0, 0.05);
    }
    

    For a very simple solution, I just copied it into my custom.css file, and changed the values of background-color, so that now I have a fancier light blue shade:

    .table-striped tbody tr:nth-of-type(odd) {
      background-color:  rgba(72, 113, 248, 0.068);
    }
    
    0 讨论(0)
  • 2020-12-01 03:13

    If you are using Bootstrap 3, you can use Florin's method, or use a custom CSS file.

    If you use Bootstrap less source instead of processed css files, you can directly change it in bootstrap/less/variables.less.

    Find something like:

    //** Background color used for `.table-striped`.
    @table-bg-accent:               #f9f9f9;
    
    0 讨论(0)
  • 2020-12-01 03:16
    .table-striped > tbody > tr:nth-child(2n+1) > td, .table-striped > tbody > tr:nth-child(2n+1) > th {
       background-color: red;
    }
    

    change this line in bootstrap.css or you could use (odd) or (even) instead of (2n+1)

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