CSS table border spacing inside only

后端 未结 7 634
心在旅途
心在旅途 2021-02-02 05:54

I have trying to work this out for months, and Google hasn\'t helped me. I\'m trying to have spacing between and tags in a table,

7条回答
  •  死守一世寂寞
    2021-02-02 05:57

    I optimized the solution with transparent border so it has no more obliquely cut inner borders.

    1) let table fill horizontal and collapse the borders:

    table {
      width: 100%;
      border-collapse: collapse;
    }
    

    2) Set all borders of table cells to width 0 and prevent background is drawn below the border.

    td {
      border: 0px solid transparent;
      background-clip: padding-box;
    }
    

    3) Set inner space with transparent border but not to first row and column.

    tr > td + td {
      border-left-width: 10px;
    }
    
    tr + tr > td {
      border-top-width: 10px;
    }
    

    here is a jsbin

提交回复
热议问题