Rounded tables in Twitter Bootstrap 3

前端 未结 10 774
清酒与你
清酒与你 2020-12-24 05:02

Bootstrap 3 has dropped rounded corners on tables. Which styles should I apply to get them back when I apply the .table-bordered class, please?

相关标签:
10条回答
  • 2020-12-24 05:34

    If you have only 1 cell in the first row or last row this one will work.

    (Added a fix to the code of: Ruben Stolk)

    .table-curved {
      border-collapse: separate;
      border: solid @table-border-color 1px;
      border-radius: @border-radius-base;
      border-left: 0px;
      border-top: 0px;
      > thead:first-child > tr:first-child > th {
        border-bottom: 0px;
        border-top: solid @table-border-color 1px;
      }
      td, th {
        border-left: 1px solid @table-border-color;
        border-top: 1px solid @table-border-color;
      }
      > :first-child > :first-child > :first-child {
        border-radius: @border-radius-base 0 0 0;
      }
      > :first-child > :first-child > :last-child {
        border-radius: 0 @border-radius-base 0 0;
      }
      > :first-child > :first-child > :only-child{
        border-radius: @border-radius-base @border-radius-base 0 0;
      }
      > :last-child > :last-child > :first-child {
        border-radius: 0 0 0 @border-radius-base;
      }
      > :last-child > :last-child > :last-child {
        border-radius: 0 0 @border-radius-base 0;
      }
      > :last-child > :last-child > :only-child{
        border-radius: 0 0 @border-radius-base @border-radius-base;
      }
    }
    
    0 讨论(0)
  • 2020-12-24 05:36

    For the sake of bootstrappiness:

    .table-curved {
        border-collapse: separate;
        border: solid @table-border-color 1px;
        border-radius: @border-radius-base;
        border-left: 0px;
        border-top: 0px;
        > thead:first-child > tr:first-child > th {
            border-bottom: 0px;
            border-top: solid @table-border-color 1px;
        }
        td, th {
            border-left: 1px solid @table-border-color;
            border-top: 1px solid @table-border-color;
        }
        > :first-child > :first-child > :first-child {
            border-radius: @border-radius-base 0 0 0;
        }
        > :first-child > :first-child > :last-child {
            border-radius: 0 @border-radius-base 0 0;
        }
        > :last-child > :last-child > :first-child {
            border-radius: 0 0 0 @border-radius-base;
        }
        > :last-child > :last-child > :last-child {
            border-radius: 0 0 @border-radius-base 0;
        }
    }
    
    0 讨论(0)
  • 2020-12-24 05:36

    Use table-bordered-curved instead table-bordered

    .table-bordered-curved {
        border-radius: 4px;
        border-collapse: separate;
        border: solid 1px #ccc;
    }
    
    .table-bordered-curved thead tr:last-child th,
    .table-bordered-curved thead tr:last-child td {
        border-bottom: solid 1px #ccc;
    }
    
    .table-bordered-curved thead tr th,
    .table-bordered-curved thead tr td {
        border-bottom: 0;
        border-right: solid 1px #ccc;
    }
    
    .table-bordered-curved thead tr th:last-child,
    .table-bordered-curved thead tr td:last-child {
        border-right: 0;
    }
    
    .table-bordered-curved tbody tr:first-child th,
    .table-bordered-curved tbody tr:first-child td {
        border-top: 0;
    }
    
    .table-bordered-curved tbody tr td {
        border-right: solid 1px #ccc;
    }
    
    .table-bordered-curved tbody tr td:last-child {
        border-right: 0;
    }
    
    0 讨论(0)
  • 2020-12-24 05:39

    The answer above on wrapping the table with a panel (<div class="panel panel-default">) seems to work the best.

    However, as mentioned in the comments, you do need to remove the top border on the table.

    I used this SCSS to do this, so thought I would share:

    // remove extra top border on tables wrapped in a panel
    .panel {
      & > .table-responsive > .table.table-bordered, & > .table.table-bordered {
        & > tbody:first-child, & > thead:first-child {
          & > tr:first-child {
            td, th {
              border-top: none;
            }
          }
        }
      }
    }
    
    0 讨论(0)
提交回复
热议问题