是否需要添加cellspacing=“0”单元格填充=“0”在<表>中?

发布于 2024-08-18 10:44:10 字数 340 浏览 6 评论 0原文

Eric meyer重置CSS建议“表仍然需要标记中的'cellspacing =“0”'”。有必要吗? border-collapse:collapse 有什么好处?和 border-spacing: 0;?

它只是建议使用 cellspacing,而 table 还有另一个称为 cellpadding 的属性?

/* tables still need 'cellspacing="0"' in the markup */
table {
        border-collapse: collapse;
        border-spacing: 0;
}

Eric meyer reset css is suggesting "tables still need 'cellspacing="0"' in the markup". Is it necessary? and what is the benefit of border-collapse: collapse; and border-spacing: 0;?

and it's only suggesting to use cellspacing, while table has another property called cellpadding?

/* tables still need 'cellspacing="0"' in the markup */
table {
        border-collapse: collapse;
        border-spacing: 0;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

一曲爱恨情仇 2024-08-25 10:44:10

不建议使用 cellpadding,因为 padding css 属性足以覆盖 cellpadding 表属性的默认属性。正如另一个答案所说,在旧版浏览器中没有兼容的 CSS 属性 cellspacing,因此将 HTML 属性作为将此设置完全“重置”为 0 的唯一方法。 border-spacing: 0; 为支持它的浏览器处理这个问题。

至于 border-collapse - 默认情况下,每个表格单元格都有自己的边框,并且 collapse 会将相邻单元格之间的边框合并在一起,给出一个(通常是单个-pixel) 网格,当 cellspacing="0" 时,这是任何其他方式都无法实现的。在普遍支持 border-collapse 之前,这就是为什么您会看到带有 cellspacing="1" 的表格,表格上有背景颜色,表格单元格上有白色背景。

border-collapse:collapse; 位于 reset.css 中只是因为它是最常见的期望结果。如果你不想要这种模式,你可以从reset.css 中删除它。

cellpadding is not suggested because the padding css property sufficiently overrides the default properties for the cellpadding table attribute. As the other answer says, there is no compatible CSS property for cellspacing in older browsers, leaving an HTML attribute as the only way to completely "reset" this setting to 0. border-spacing: 0; takes care of this for browsers which do support it.

As for border-collapse — by default, table cells each have their own border, and collapse will merge the borders between adjacent cells together, giving the appearance of a (usually single-pixel) grid, which isn't achievable any other way when cellspacing="0". Before border-collapse was commonly supported, this is why you'd see tables with cellspacing="1" and a background color on the table, and white backgrounds on table cells.

border-collapse:collapse; is in the reset.css simply because it is the most common desired result. If you don't want this mode, you'd be fine removing this from the reset.css.

南城追梦 2024-08-25 10:44:10

Internet Explorer 6 7,可能还有其他早期浏览器,无法识别 border-spacing 属性,因此,他建议您仍然在 HTML 中提供值。

查看 SitePoint 上的兼容性表

Internet Explorer 6 and 7, and probably other early browsers, do not recognize the border-spacing attribute and as such, he suggests you still supply the values in the HTML as well.

Check out the compatibility table on SitePoint

葵雨 2024-08-25 10:44:10

表格中有两种类型的边框,表格本身可以有边框(外部边框和单元格之间的边框),每个单元格周围可以有边框。

使用 border-collapse:collapse; 意味着两个相邻的具有相同边框设置的单元格只会获得一组边框而不是双边框,例如一个单元格的右边框将折叠为行中下一个单元格的左边框。

在 CSS 2 之前,单元格之间的表格边框没有 CSS 样式,因此必须使用表格上的 HTML 属性 cellspacing="0" 禁用它,以支持 IE 7* 等较旧的浏览器。如果单元格之间存在表格边框,则边框折叠自然不会起作用,因为边框不彼此相邻。

* 我真的很享受将 IE 7 称为“旧版浏览器”的感觉;)

There are two types of borders in a table, the table itself can have borders (outer borders and borders between cells), and each cell can have borders around them.

Using border-collapse: collapse; means that two cells with the same border settings next to each other will only get a single set of bordering instead of a double, e.g. the right border of one cell will collapse with the left border on the next cell in the row.

There wes no CSS style for the table border between cells until CSS 2, so it has to be disabled using the HTML attribute cellspacing="0" on the table to support older browsers like IE 7*. If there is table borders between the cells, the border collapsing will naturally not work as the borders are not next to each other.

* I truly enjoyed the feeling of calling IE 7 an "older browser" ;)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文