CSS table border spacing inside only

后端 未结 7 733
心在旅途
心在旅途 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 06:17

    Had the same problem, the border spacing property was adding space around the table as well, and to my knowledge, there wasn’t anyway to limit it to only ‘the inside’, so I used transparent borders instead:

    table td {
       border-left: 1em solid transparent;
       border-top: 1em solid transparent;
    }
    

    This sets ‘border spacing’ as normal, except that there’s ‘unwanted’ spacing at the top and left of the table.

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

    Selects the first column.

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

    Selects the td elements of the first row (assuming that the top of the table starts with a tr element, change accordingly for th).

提交回复
热议问题