http://jsfiddle.net/fQv97/
<div class="table-cell">
My text, should be align middle
</div>CSS
.table-cell {
height: 200px;
width: 200px;
vertical-align: middle;
background: #eee;
display: table-cell;
position: absolute;
}问题
文本应该放在我的“表格单元格”的中间。一切按预期工作,直到我加上“职位:绝对”。现在它不能再把我的内容放在中间了?为什么不行?它仍然知道我的高度和宽度,因为我在我的CSS设置它。
有什么解决办法吗?
发布于 2012-01-17 15:25:58
一切按预期工作,直到我加上“职位:绝对”。现在它不能再把我的内容放在中间了?为什么不行?
position: absolute强迫display: block,读二号这里。
至于解决办法,我认为您必须将其包装在另一个元素中:
<div class="table-cell-wrapper">
<div class="table-cell">
My text, should be align middle
</div>
</div>
.table-cell-wrapper {
position: absolute;
}
.table-cell {
height: 200px;
width: 200px;
vertical-align: middle;
background: #eee;
display: table-cell;
}发布于 2012-01-17 15:15:09
为此,我发现了一些解决办法,比如在位置之前添加一个散列:
#position: absolute;那个黑客是在这里发现的:CSS垂直对中
发布于 2012-01-17 15:32:10
以下是解决办法:
<div style="position: absolute; /*your position*/">
<div class="table-cell">
My text, should be align middle
</div>
</div>https://stackoverflow.com/questions/8896965
复制相似问题