使用 XHTML 1.0 Transitional 的表格样式
我正在尝试向 XHTML 1.0 Transitional 网页的表格行添加边框和填充(请参阅下面的代码进行重现)。我知道,如果我将页面类型更改为其他类型,我将能够向表行和单元格添加边框和填充。但在 XHTML 1.0 Transitional 中,它根本不起作用。
考虑到我无法更改 DOCTYPE,我应该如何向表格添加边框和填充?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<style>
table
{
border: solid 1px black;
}
tr
{
/* Doesn't work */
margin: 10px;
border: solid 1px black;
}
</style>
</head>
<body>
<table>
<tbody>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
<tr>
<td>4</td>
<td>5</td>
<td>6</td>
</tr>
</tbody>
</table>
</body>
</html>
I am trying to add a border and padding to the table row of XHTML 1.0 Transitional web page (see code below to repro). I know that if I change the type of page to something else, I will be able to add borders and padding to the table rows and cells. But in XHTML 1.0 Transitional, it doesn't work at all.
Considering that I can't change the DOCTYPE, what am I suppose to do add a border and padding to the table?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<style>
table
{
border: solid 1px black;
}
tr
{
/* Doesn't work */
margin: 10px;
border: solid 1px black;
}
</style>
</head>
<body>
<table>
<tbody>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
<tr>
<td>4</td>
<td>5</td>
<td>6</td>
</tr>
</tbody>
</table>
</body>
</html>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试查看边框和边距在 td 上是否有效。
如果是这样,您必须仅将其设置为中心单元格的顶部/底部边距。
Try seeing if the border and margin works on the td.
If it does you'll have to make it top/bottom margin only for center cells.
如果您希望它们围绕每个单元格,请将样式应用于 td 元素,而不是 tr:假设您希望将其应用于 tr,我不完全确定为什么会这样,但是向表格添加 border-collapse 将使 tr边框工作:
对于边距,我会向 td 元素应用填充:
If you want them around each cell, apply the style to the td element, not the tr: Assuming you want it on the tr, I'm not entirely sure why this works, but adding border-collapse to the table will make the tr border work:
For the margins, I'd go with applying padding to the td elements: