【发布时间】:2014-12-04 00:30:39
【问题描述】:
我在特定大小的 div 中有一个 html 表格。我希望表格应用边距折叠并 100% 宽。这是我的代码。它在 IE8 中呈现我想要的效果,而在 Firefox 中却不正确。 Firefox 可能正确地执行规范,但无论如何。如何修复我的 css 以在两种浏览器中工作?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Untitled 1</title>
<style type="text/css">
table
{
border-collapse: collapse;
border-spacing: 0;
}
table
{
margin: 10px 0;
width: 100%;
display: block;
}
p
{
margin: 10px 0;
}
td, th
{
border: 1px solid #000000;
}
</style>
</head>
<body>
<div style="width: 600px; border: 1px purple solid;">
<p>Some text at the top. Notice that the margin collapse does not work unless display:block.</p>
<table>
<tr>
<th></th>
<th>Header 1</th>
<th>Header 2</th>
<th>Header 3</th>
</tr>
<tr>
<td>Label 1</td>
<td>1.A</td>
<td>1.B</td>
<td>1.c</td>
</tr>
<tr>
<td>Label 2</td>
<td>2.A</td>
<td>2.B</td>
<td>2.c</td>
</tr>
</table>
<p>Some text at the bottom. Notice that the margin collapse does not work unless display:block. Its stupid.</p>
</div>
</body>
</html>
我需要用于边距折叠的 display:block 才能在 Firefox 中工作。如果您删除 display:block,您应该注意到<p> 标签之间的间距从 10px 扩大到 20px。
这也是对我之前发布的this 问题的编辑,但由于某种原因它不允许我编辑。我一直在搞乱我的互联网缓存,所以我可能搞砸了一个 cookie。
【问题讨论】:
-
移除显示:块;来自css