How to set cellpadding and cellspacing in table with CSS?

This question already has an answer here:

  • Set cellpadding and cellspacing in CSS? 26 answers

  • Use padding on the cells and border-spacing on the table. The former will give you cellpadding while the latter will give you cellspacing.

    table { border-spacing: 5px; } /* cellspacing */
    
    th, td { padding: 5px; } /* cellpadding */
    

    jsFiddle Demo


    The padding inside a table-divider (TD) is a padding property applied to the cell itself.

    CSS

    td, th {padding:0}
    

    The spacing in-between the table-dividers is a space between cell borders of the TABLE. To make it effective, you have to specify if your table cells borders will 'collapse' or be 'separated'.

    CSS

    table, td, th {border-collapse:separate}
    table {border-spacing:6px}
    

    Try this : https://www.google.ca/search?num=100&newwindow=1&q=css+table+cellspacing+cellpadding+site%3Astackoverflow.com ( 27 100 results )


    Here is the solution.

    The HTML:

    <table cellspacing="0" cellpadding="0">
        <tr>
            <td>
                123
            </td>
        </tr>
    </table>
    

    The CSS:

    table { 
          border-spacing:0; 
          border-collapse:collapse;   
        }
    

    Hope this helps.

    EDIT

    td, th {padding:0}
    
    链接地址: http://www.djcxy.com/p/16940.html

    上一篇: 在html中插入一个或多个空格

    下一篇: 如何在CSS中设置cellpadding和cellpacing?