中?" />

使用 cellpadding="2" 可以吗?单元格间距=“2”在<表>中?

发布于 2024-08-24 17:28:05 字数 676 浏览 6 评论 0 原文

中使用 cellpadding="2" cellspacing="2" 可以吗?或者这些不是 W3C 推荐的并且不符合 Web 标准?

CSS 中有哪些替代方案?

更新:使用 也可以吗?

我的问题是关于内容和表示的分离以及 W3C 建议。

更新根据中的此图表仅align 和 bgcolor。那么允许

的其他属性可以吗?

替代文本 http://shup.com/Shup/293811/11021055643-My-Desktop .png

Is it ok to use cellpadding="2" cellspacing="2" in <table>? Or are these not recommended by W3C and not right according to web standards?

What are alternatives in CSS?

Update: and is it also ok to use <td align="right" valign="top">?

My question is in terms of separation of content and presentation and W3C recommendations.

Update:
According to this chart in <table> only align and bgcolor are not allowed in Strict version. So is it ok to allow other properties of <table>?

alt text http://shup.com/Shup/293811/11021055643-My-Desktop.png

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

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

发布评论

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

评论(4

天冷不及心凉 2024-08-31 17:28:06

单元格填充和单元格间距属性仍然受到完全支持。尽管有些人会告诉您通过 CSS 设置表格单元格上的填充和边距来实现此目的,但这仍然是将其应用于表格中的每个单元格的简单方法。

如果您想要一份属性列表以及哪些属性已弃用,我发现 w3schools 是最可靠的信息来源。

w3schools:td 标签

w3schools:表格标签

The cell-padding and cell-spacing properties are still fully supported. Although some people will tell you to do it with CSS setting padding and margin on the table cells, this is still the easy way to have it applied to every cell in a table.

If you want a list of properties and which ones are deprecated, I find w3schools to be the most reliable source of information.

w3schools: td tag

w3schools: table tag

╭ゆ眷念 2024-08-31 17:28:05

不,这些属性并未被正式弃用,但通常不受欢迎,因为您应该使用 CSS 进行演示。

对于cellpadding,您可以轻松地将其替换为CSS中的padding

table.classname td {
  padding: 4px;
}

对于cellspacing,首先确定它是否确实有必要。如果表格单元格上没有任何边框,或者您不希望每个单元格的边框之间有间距,那么它就不是。 (我个人认为单元格间距在设计方面看起来很糟糕,但在某些情况下可能很有用。)

这样做非常好:

table {
  border-collapse: collapse;
}

然后每个表格单元格与其邻居共享边框,这意味着您可以添加 1px 顶部和底部边框,每行之间仅间隔 1 像素。

然而,要分离边框,您可以使用此 CSS,尽管它可能在 IE6 中不起作用。

table.data td {
  border-collapse: separate;
  border-spacing: 4px;
}

No, the attributes are not officially deprecated but they are generally frowned upon, since you should use CSS for presentation.

For cellpadding you can easily replace it with padding in CSS:

table.classname td {
  padding: 4px;
}

For cellspacing, first decide if it's really necessary. If you don't have any borders on the table cells, or you don't want spacing between the borders of each cell then it isn't. (Personally I think cell spacing looks bad design-wise, but it may be useful in some circumstances.)

It's quite nice to do this:

table {
  border-collapse: collapse;
}

Then each table cell shares the border with its neighbour, meaning you can add, say, 1px top and bottom borders and you just get 1px separating each row.

To separate borders, however, you can use this CSS, though it probably doesn't work in IE6.

table.data td {
  border-collapse: separate;
  border-spacing: 4px;
}
未蓝澄海的烟 2024-08-31 17:28:05

虽然技术上很好,但强烈不推荐。

想象一下,如果您的网站在多个页面上有许多表格,并且您出于某种原因想要更改填充或间距。那么,您必须浏览整个网站并进行更改。

或者,您可以使用 CSS,通过更改一个位置的一行代码来更改整个网站。这不仅效率更高,而且更容易,可以帮助您避免错误,并使您保持一致。

<style type="text/css">
    table td { padding:10px; margin:10px; }
</style>

如果您想使用一些带有填充和边距的表格,而另一些则没有,您可以通过添加“.”在 CSS 中创建类。在您选择的名称之前:

<style type="text/css">
    .myTable td { padding:10px; margin:10px; }
</style>
<table class="myTable> etc...

请注意,类名称区分大小写。还有许多其他属性可供您使用,例如边框、背景颜色等。

简而言之,虽然单元格间距和单元格填充属性并未弃用,但使用 CSS 会更好,以便在整个项目中实现轻松和一致。地点。

While it's technically fine, it is strongly not recommended.

Imagine if your site had many tables across many pages and you wanted to change the padding or the spacing for one reason or another. Well, you would have to go through your entire site and make the changes.

Or you can use CSS and change your entire site by changing a line of code in one location. This is not only far more efficient, but its easier, helps you avoid mistakes, and keeps you consistent.

<style type="text/css">
    table td { padding:10px; margin:10px; }
</style>

If you want to use some tables with padding and margins and others without, you can create classes in your CSS by adding a "." before a name of your choice:

<style type="text/css">
    .myTable td { padding:10px; margin:10px; }
</style>
<table class="myTable> etc...

Note that class names are case sensitive. There are also many other attributes you can have fun with like border, background-color, etc...

In short, while cell-spacing and cell-padding attributes are not deprecated, its far better to use CSS for ease and consistency across your site.

梦巷 2024-08-31 17:28:05
<style type="text/css">
table.padded-table td { 
    padding:10px; 
    }
</style>
<style type="text/css">
table.padded-table td { 
    padding:10px; 
    }
</style>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文