How can I apply a border only inside a table?

前端 未结 9 503
盖世英雄少女心
盖世英雄少女心 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:32

    Add the border to each cell with this:

    table > tbody > tr > td { border: 1px solid rgba(255, 255, 255, 0.1); }
    

    Remove the top border from all the cells in the first row:

    table > tbody > tr:first-child > td { border-top: 0; }
    

    Remove the left border from the cells in the first column:

    table > tbody > tr > td:first-child { border-left: 0; }
    

    Remove the right border from the cells in the last column:

    table > tbody > tr > td:last-child { border-right: 0; }
    

    Remove the bottom border from the cells in the last row:

    table > tbody > tr:last-child > td { border-bottom: 0; }
    

    http://jsfiddle.net/hzru0ytx/

提交回复
热议问题