HTML 表格定位和列间距

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12186599/
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 02:34:02  来源:igfitidea点击:

HTML Table positioning and column spacing

htmlhtml-table

提问by Slurms

In the "table style" portion of my code, is there a way for me to adjust the space between the columns in a table? Also, what attribute should I put in to make sure the tables position is aligned completely to the left and top?

在我的代码的“表格样式”部分,有没有办法调整表格中列之间的空间?另外,我应该输入什么属性来确保表格位置完全与左侧和顶部对齐?

<table style="width: 960px; height: 81px;" border="0">

回答by j08691

For current and future compatibility use CSS:

为了当前和未来的兼容性,请使用 CSS:

// cellspacing
table { border-collapse:separate; border-spacing: 5px; }

To make sure the table is aligned to the left and top, remove any top and left margins. You might also want to change the positioning (position:relative or position:absolute) based on where the table need to exist.

要确保表格与左侧和顶部对齐,请删除所有顶部和左侧边距。您可能还想根据表需要存在的位置更改定位(位置:相对或位置:绝对)。

Ref: border-collapse| border-spacing

参考:border-collapse| 边框间距

回答by Diodeus - James MacFarlane

cellpaddingcontrols the gaps inside cells and cellspacingcontrols the space between them.

cellpadding控制单元格内部的间隙并cellspacing控制它们之间的空间。

<table style="width: 960px; height: 81px;" border="0" cellpadding="0" cellspacing="0">

As for alignment, you control this within table cells:

至于对齐,您可以在表格单元格中控制它:

<td align="left" valign="top">

回答by Aghilas Yakoub

you can try with cellspacing property in order to create space

您可以尝试使用 cellpacing 属性来创建空间