Html 如何在 HTML5 上使用 cellpadding 和 cellpacing?

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

How to use cellpadding and cellspacing on HTML5?

csshtml

提问by Hatem

Am trying to use CSS3 to set the cell-spacing and the cell-padding for my table since HTML5 doesn't support these attributes.

我正在尝试使用 CSS3 为我的表格设置单元格间距和单元格填充,因为 HTML5 不支持这些属性。

I have found many resources on the internet says that you should use border-spacing and padding using CSS.

我在互联网上发现很多资源都说你应该使用 CSS 使用边框间距和填充。

Unfo. i tried all these tricks , but it seems that no thing changing at all. The spacing is very important because am including image structure on the different cell of the table.

取消。我尝试了所有这些技巧,但似乎没有任何改变。间距非常重要,因为包括表格不同单元格上的图像结构。

So how i can solve it now ? plz need your help

那么我现在该如何解决呢?lz需要你的帮助

#SearchTable
{
    border-collapse: collapse;
    padding:0px 0px 0px 0px;
}

#SearchTable td 
{
    padding:0;
    border-spacing:0px 0px; 
}

回答by Matt Parkins

For cellspacing:

对于单元格间距:

  1. Set border-spacing on the table, not on the td.
  2. Set border-collapse to separate.
  1. 在桌子上设置边框间距,而不是在 td 上。
  2. 将边框折叠设置为分离。
#SearchTable {
   border-collapse: separate;
   border-spacing: 8px; 
}

回答by Jukka K. Korpela

You have not set id=SearchTableon the table, or you have some other stylesheet rules that override those that you specify. As such, the rules you posted are more than sufficient for the effect; you only need

您没有id=SearchTable在表上设置,或者您有一些其他样式表规则覆盖了您指定的规则。因此,您发布的规则足以达到效果;你只需要

#SearchTable
{
    border-collapse: collapse;
}

#SearchTable td 
{
    padding:0;
}

(which are already in CSS2).

(已经在 CSS2 中)。

回答by Binil

You need to set it like this. It worked for me.

你需要这样设置。它对我有用。

#SearchTable {
    border-spacing:2px 2px;
    border-collapse:separate;
}

#SearchTable td {
    border:1px solid black;
}