表格cellspacing与CSS

时间:2010-03-26 09:19:50

标签: html css css-tables

是否可以在细胞之间添加间距?

<!DOCTYPE html>
<html>
 <head>
  <meta charset="utf-8" />
  <title>test</title>
  <style>
   #wrap {
    display: table-row;
    /* there is no also cellspacing in CSS afaik :( */
   }
   #wrap div {
    display: table-cell;
    /* margin: 40px; doesn't work for table-cell :( */
    /* border: 30px solid transparent; works but it's as good as adding padding */
    /* border: 30px solid white; works but the page background is invisible */

    /* decoration: */
    background-color: green;
    padding: 20px;
   }
  </style>
 </head>
 <body>
  <!-- don't touch the markup -->
  <div id="wrap">
   <div>text1</div>
   <div>text2</div>
  </div>
 </body>
</html>

1 个答案:

答案 0 :(得分:4)

使用margin属性:

#wrap div {
background-color:green;
float:left;
margin:10px;
padding:20px;
}

如果这不是您想要达到的目的,请告诉我,以便我可以提供帮助。

编辑:另一种方法是:

#wrap {
border-spacing:20px;
display:inline-table;
}

但请注意,并非所有浏览器都完全支持边框间距(IE6和IE7不支持它)。