Html 如何仅水平设置表格中的单元格间距

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12970826/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 03:28:44  来源:igfitidea点击:

How to set cellspacing in tables only horizontally

htmlcsshtml-tablecellspacing

提问by Borut Flis

I would like to style the table written below.

我想设计下面写的表格。

<table border="1"   cellspacing="10">
  <tr>
    <th>Month</th>
    <th>Savings</th>  
  </tr>
  <tr>
    <td>January</td>
    <td>0</td>
  </tr>
</table>

The problem is that cellspacing sets the space between cells both horizontaly and verticaly, I would like it to be done only horizontaly. Is there a way to do this.

问题是 cellpacing 设置了水平和垂直的单元格之间的空间,我希望它只能水平完成。有没有办法做到这一点。

回答by Jukka K. Korpela

Use the border-spacingCSS property on the table. Browser support is fairly good (excluding mainly IE up to and including IE 7). Example:

使用border-spacing表格上的 CSS 属性。浏览器支持相当好(主要不包括 IE,包括 IE 7)。例子:

table { border-spacing: 10px 0; }

回答by Murali Murugesan

Try CSS

试试 CSS

table td{

 padding:0px 10px 0px 10px; /* top right bottom left */

 }