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

后端 未结 12 1249
温柔的废话
温柔的废话 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 02:49

    You have two options, either you override the styles with a custom stylesheet, or you edit the main bootstrap css file. I prefer the former.

    Your custom styles should be linked after bootstrap.

    <link rel="stylesheet" src="bootstrap.css">
    <link rel="stylesheet" src="custom.css">
    

    In custom.css

    .table-striped>tr:nth-child(odd){
       background-color:red;
    }
    
    0 讨论(0)
  • 2020-12-01 02:54

    Easiest way for changing order of striped:

    Add empty tr before your table tr tags.

    0 讨论(0)
  • 2020-12-01 02:55

    Delete table-striped Its overriding your attempts to change row color.

    Then do this In css

       tr:nth-child(odd) {
        background-color: lightskyblue;
        }
    
       tr:nth-child(even) {
        background-color: lightpink;
        }
    
        th {
           background-color: lightseagreen;
        }
    
    0 讨论(0)
  • 2020-12-01 02:56

    If using SASS and Bootstrap 4, you can change the alternating background row color for both .table and .table-dark with:

    $table-accent-bg: #990000;
    $table-dark-accent-bg: #990000;
    
    0 讨论(0)
  • 2020-12-01 02:57

    Add the following CSS style after loading Bootstrap:

    .table-striped>tbody>tr:nth-child(odd)>td, 
    .table-striped>tbody>tr:nth-child(odd)>th {
       background-color: red; // Choose your own color here
     }
    
    0 讨论(0)
  • 2020-12-01 02:59

    I found this checkerboard pattern (as a subset of the zebra stripe) to be a pleasant way to display a two-column table. This is written using LESS CSS, and keys all colors off the base color.

    @base-color: #0000ff;
    @row-color: lighten(@base-color, 40%);    
    @other-row: darken(@row-color, 10%);
    
    tbody {
        td:nth-child(odd) { width: 45%; }
        tr:nth-child(odd) > td:nth-child(odd) {
            background: darken(@row-color, 0%); }
        tr:nth-child(odd) > td:nth-child(even) {
            background: darken(@row-color, 7%); }
        tr:nth-child(even) > td:nth-child(odd) {
            background: darken(@other-row, 0%); }
        tr:nth-child(even) > td:nth-child(even) {
            background: darken(@other-row, 7%); }
    }
    

    Note I've dropped the .table-striped, but doesn't seem to matter.

    Looks like: enter image description here

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