Set cellpadding and cellspacing in CSS?

前端 未结 28 1447
暖寄归人
暖寄归人 2020-11-22 02:15

In an HTML table, the cellpadding and cellspacing can be set like this:

28条回答
  •  春和景丽
    2020-11-22 02:30

    Default

    The default behavior of the browser is equivalent to:

    table {border-collapse: collapse;}
    td    {padding: 0px;}
    

             Enter image description here

    Cellpadding

    Sets the amount of space between the contents of the cell and the cell wall

    table {border-collapse: collapse;}
    td    {padding: 6px;}
    

            Enter image description here

    Cellspacing

    Controls the space between table cells

    table {border-spacing: 2px;}
    td    {padding: 0px;}
    

            Enter image description here

    Both

    table {border-spacing: 2px;}
    td    {padding: 6px;}
    

            Enter image description here

    Both (special)

    table {border-spacing: 8px 2px;}
    td    {padding: 6px;}
    

            Enter image description here

    Note: If there is border-spacing set, it indicates border-collapse property of the table is separate.

    Try it yourself!

    Here you can find the old HTML way of achieving this.

提交回复
热议问题