html - 显示 : table-cell issue in Firefox

标签 html css

我有一个带有 H1 的 div 和一个段落。挑战在于将段落垂直居中。

<div id="id1">
<h1>Header</h1>
<p>paragraph</p>
</div>

我使用:

#id1
{
position: relative;
width: 250px;
height: 250px;
border-radius: 125px;
background: #000;
color: #f00;
}
#id1 h1
{
position: relative;
margin: 0;
padding: 0;
text-align: center;
top: -50px;
}
#id1 p
{
position: relative;
display: table-cell;
vertical-align: middle;
top: -37px;
margin: 0;
padding: 0;
text-align: center;
height: 250px;
width: 250px;
border-radius: 125px;
background: #fff;
color: #000;
}

它适用于大多数新浏览器(甚至 IE8),但不适用于 FF。 我想问题是由于 H1 和 P 的相对位置。但不确定。 请帮助我!

fiddle

最佳答案

您的 h1 标签包含文本,FF 将文本高度添加到标题。尝试删除文本,请参阅[此处][http://jsfiddle.net/G3av6/3/]

关于html - 显示 : table-cell issue in Firefox,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20339371/

相关文章:

html - CSS 到 class + anyclass

jquery - 动态滑动div

html - 如何用 Twitter Bootstrap 导航栏上的图像替换品牌文本?

jquery - 如果我的 html 文件中有超过 1 个 select2,如何更改特定 select2 的宽度?

html - 移动优先设计和打印

jquery - 搜索输入滑出按钮悬停 CSS3?

html - CSS 下划线悬停 - 为什么填充下划线?

css - 在包含路径的 svg 选定部分上旋转动画

html - 将鼠标悬停在链接上时绘制带跨度的线

html - 像 <section> 和 <article> 这样的新 HTML5 元素毫无意义吗?