【发布时间】:2013-03-07 00:13:23
【问题描述】:
我正在使用Chris Coyier suggested in CSS-tricks 方法将一些内容(双向)置于容器元素内的中心。为了兼容性,我使用语义方法而不是文章中使用的:before 伪元素。出于某种原因,Firefox(在 v.19 for Mac 上测试)失败了,我无法弄清楚正确的修复方法是什么(而 Safari、Opera、IE9 和 Chrome 都可以正常工作)。
我可以检测浏览器并设置一些条件规则,但如果可能的话,我有兴趣在全局范围内修复此问题。
如果你想在不同的浏览器中查看,这是我来自 the modified fiddle I created 的代码。
CSS:
.block {
text-align: center;
background: #c0c0c0;
margin: 20px 0;
height: 300px;
}
.content-before {
content:'';
display: inline-block;
height: 100%;
vertical-align: middle;
margin-right: -0.25em; /* Adjusts for spacing */
}
.centered {
display: inline-block;
vertical-align: middle;
padding: 10px;
background: #f5f5f5;
}
HTML:
<div>
<div class="block">
<span class="content-before"></span>
<div class="centered">
<h1>Some text</h1>
<p>But he stole up to us again, and suddenly clapping
his hand on my shoulder, said—"Did ye see anything
looking like men going towards that ship a while ago?"</p>
</div>
</div>
</div>
【问题讨论】: