Set cellpadding and cellspacing in CSS?

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

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

28条回答
  •  隐瞒了意图╮
    2020-11-22 02:37

    You can easily set padding inside the table cells using the CSS padding property. It is a valid way to produce the same effect as the table's cellpadding attribute.

    table,
    th,
    td {
      border: 1px solid #666;
    }
    
    table th,
    table td {
      padding: 10px;
      /* Apply cell padding */
    }
    
    
    
    
      
      Set Cellpadding in CSS
    
    
    
    
    
      
Row First Name Last Name Email
1 Clark Kent clarkkent@mail.com
2 Peter Parker peterparker@mail.com
3 John Rambo johnrambo@mail.com

Similarly, you can use the CSS border-spacing property to apply the spacing between adjacent table cell borders like the cellspacing attribute. However, in order to work border-spacing the value of border-collapse property muse be separate, which is default.

table {
  border-collapse: separate;
  border-spacing: 10px;
  /* Apply cell spacing */
}

table,
th,
td {
  border: 1px solid #666;
}

table th,
table td {
  padding: 5px;
  /* Apply cell padding */
}




  
  Set Cellspacing in CSS





  
Row First Name Last Name Email
1 Clark Kent clarkkent@mail.com
2 Peter Parker peterparker@mail.com
3 John Rambo johnrambo@mail.com

提交回复
热议问题