使用 cellpadding="2" 可以吗?单元格间距=“2”在<表>中?
在 中使用
cellpadding="2" cellspacing="2"
可以吗?或者这些不是 W3C 推荐的并且不符合 Web 标准?
CSS 中有哪些替代方案?
更新:使用
也可以吗?
我的问题是关于内容和表示的分离以及 W3C 建议。
更新:
根据中的此图表仅
align 和
bgcolor
。那么允许 的其他属性可以吗?
替代文本 http://shup.com/Shup/293811/11021055643-My-Desktop .png
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
单元格填充和单元格间距属性仍然受到完全支持。尽管有些人会告诉您通过 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
不,这些属性并未被正式弃用,但通常不受欢迎,因为您应该使用 CSS 进行演示。
对于
cellpadding
,您可以轻松地将其替换为CSS中的padding
:对于
cellspacing
,首先确定它是否确实有必要。如果表格单元格上没有任何边框,或者您不希望每个单元格的边框之间有间距,那么它就不是。 (我个人认为单元格间距在设计方面看起来很糟糕,但在某些情况下可能很有用。)这样做非常好:
然后每个表格单元格与其邻居共享边框,这意味着您可以添加 1px 顶部和底部边框,每行之间仅间隔 1 像素。
然而,要分离边框,您可以使用此 CSS,尽管它可能在 IE6 中不起作用。
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 withpadding
in CSS: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:
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.
虽然技术上很好,但强烈不推荐。
想象一下,如果您的网站在多个页面上有许多表格,并且您出于某种原因想要更改填充或间距。那么,您必须浏览整个网站并进行更改。
或者,您可以使用 CSS,通过更改一个位置的一行代码来更改整个网站。这不仅效率更高,而且更容易,可以帮助您避免错误,并使您保持一致。
如果您想使用一些带有填充和边距的表格,而另一些则没有,您可以通过添加“.”在 CSS 中创建类。在您选择的名称之前:
请注意,类名称区分大小写。还有许多其他属性可供您使用,例如边框、背景颜色等。
简而言之,虽然单元格间距和单元格填充属性并未弃用,但使用 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.
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:
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.