是否可以使用cellpadding =“2” cellspacing =“2”在< table&gt ;? [英] Is it ok to use cellpadding="2" cellspacing="2" in <table>?

查看:571
本文介绍了是否可以使用cellpadding =“2” cellspacing =“2”在< table&gt ;?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

< table> 中使用 cellpadding =2cellspacing =2



CSS中的替代方法是什么?



更新:也可以使用< td align =rightvalign =top>

我的问题是在分离内容和演示文稿以及W3C推荐方面。



>更新
根据此图表,<$ ccr c> c $ c>< table> 只允许 align bgcolor 版。允许其他属性< table>



解决方案

否,属性没有正式弃用,但他们通常皱眉,因为你应该使用CSS的演示文稿。



对于 cellpadding ,您可以轻松地替换为 padding 在CSS中:

  table.classname td {
padding:4px;
}

对于 cellspacing 首先决定它是否真的有必要。如果你没有在表格单元格上的任何边框,或者你不想要在每个单元格的边框之间的间距,那么它不是。 (个人而言,我认为单元间距在设计上看起来不错,但在某些情况下它可能会有用。)



这是非常好的:

 表{
border-collapse:collapse;
}

然后每个表单元格与其邻居共享边界,比如1px的顶部和底部边框,你只是得到1px分隔每一行。



然而,为了分离边框,你可以使用这个CSS,虽然它可能不工作

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


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>?

解决方案

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;
}

这篇关于是否可以使用cellpadding =“2” cellspacing =“2”在&lt; table&gt ;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆