How can I apply a border only inside a table?

前端 未结 9 467
盖世英雄少女心
盖世英雄少女心 2020-11-30 17:24

I am trying to figure out how to add border only inside the table. When I do:

table {
    border: 0;
}
table td, table th {
    border: 1px solid black;
}
         


        
9条回答
  •  有刺的猬
    2020-11-30 17:56

    For ordinary table markup, here's a short solution that works on all devices/browsers on BrowserStack, except IE 7 and below:

    table { border-collapse: collapse; }
    
    td + td,
    th + th { border-left: 1px solid; }
    tr + tr { border-top: 1px solid; }
    

    For IE 7 support, add this:

    tr + tr > td,
    tr + tr > th { border-top: 1px solid; }
    

    A test case can be seen here: http://codepen.io/dalgard/pen/wmcdE

提交回复
热议问题