Rounded tables in Twitter Bootstrap 3

前端 未结 10 773
清酒与你
清酒与你 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:14

    I assume you are not using the source less-files. However, in normalize.less, bootstrap 3.0RC is adding:

    // ==========================================================================
    // Tables
    // ==========================================================================
    
    //
    // Remove most spacing between table cells.
    //
    
    table {
      border-collapse: collapse;
      border-spacing: 0;
    }
    

    This border-collapse thing destroys the rounded borders on tables. So, by simply override that in your table-bordered you turn on the effect:

    .table-bordered
    {
        -webkit-border-radius: 4px;
        -moz-border-radius: 4px;
        border-radius: 4px;
    
        border-collapse: inherit;
    }
    

    I think it may work.

    0 讨论(0)
  • 2020-12-24 05:16

    The following one works quite nicely for me:

    .table-curved {
        border-collapse: separate;
    }
    .table-curved {
        border: solid #ccc 1px;
        border-radius: 6px;
    }
    .table-curved td, .table-curved th {
        border-left: 1px solid #ccc;
        border-top: 1px solid #ccc;
    }
    .table-curved tr > *:first-child {
        border-left: 0px;
    }
    .table-curved tr:first-child > * {
        border-top: 0px;
    }
    

    Though it does not of course work for nested tables.

    0 讨论(0)
  • 2020-12-24 05:17

    This is another solution that may be far simpler than the above ones. This will select the first and last th elements and apply a border to their respective corners. You can then add a radius to the overall table.

    .table {
      border-radius: 5px;
    }
    th:first-of-type {
      border-top-left-radius: 5px;
    }
    th:last-of-type {
      border-top-right-radius: 5px;
    }
    
    0 讨论(0)
  • 2020-12-24 05:20

    "table-responsive" goes on a div that wraps the table, not on the table itself.

    In normalize.less there is the table reset which include border-collapse:collapse. This was not in the 2.x of Bootstrap. Because of this new reset, there are no rounded corners as those have to be border-collapse:separate. You have to make a separate class and set it up accordingly.

           <table class="table table-curved">
    

    Only works with "table-hover" and "table-striped" NOT table-bordered. The borders are included in this style.

    .table-curved {
        border-collapse: separate;
    }
    .table-curved {
        border: solid #ccc 1px;
        border-radius: 6px;
        border-left:0px;
    }
    .table-curved td, .table-curved th {
        border-left: 1px solid #ccc;
        border-top: 1px solid #ccc;
    }
    .table-curved th {
        border-top: none;
    }
    .table-curved th:first-child {
        border-radius: 6px 0 0 0;
    }
    .table-curved th:last-child {
        border-radius: 0 6px 0 0;
    }
    .table-curved th:only-child{
        border-radius: 6px 6px 0 0;
    }
    .table-curved tr:last-child td:first-child {
        border-radius: 0 0 0 6px;
    }
    .table-curved tr:last-child td:last-child {
        border-radius: 0 0 6px 0;
    }
    

    LESS

      //  Added Rounded Corner Tables 
    .table-curved {
      border-collapse: separate;
      border: solid @table-border-color 1px;
      border-radius: @table-radius;
      border-left:0px;
    
        td, th {
          border-left: 1px solid @table-border-color;
          border-top: 1px solid @table-border-color;
        }
    
        th {
          border-top: none;
        }
    
        th:first-child {
          border-radius: @table-radius 0 0 0;
        }
    
        th:last-child {
          border-radius: 0 @table-radius 0 0;
        }
    
        th:only-child{
          border-radius: @table-radius @table-radius 0 0;
        }
    
        tr:last-child td:first-child {
          border-radius: 0 0 0 @table-radius;
        }
    
        tr:last-child td:last-child {
          border-radius: 0 0 @table-radius 0;
        }
    }
    
    0 讨论(0)
  • 2020-12-24 05:21

    Using Christina's answer and this thread , i came up with this CSS to get the rounded corners in tables with or without THEAD.

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

    If you surround the table with a panel you get your rounded corners.

    Like this:

    <div class="panel panel-default">
        <table class="table table-bordered">
            ....
        </table>
    </div>
    
    0 讨论(0)
提交回复
热议问题