亲爱的专家,我试图通过CSS将一个段落与一个分区元素的中间对齐,我不知道怎么能让它工作.
<style type="text/css"> .wrap{ background:red; height: 5em; } p{ background:blue; height: 2em; vertical-align:middle; } </style> <div class="wrap"> <p> ALIGN TEXT </p> </div>
它在IE或Firefox中都不起作用,
解决方法
Here’s a nice hackish example,我把IE css放在条件中而不是用黑客隐藏它,其他那个很好.
<div style="display: table; height: 400px; #position: relative; overflow: hidden;"> <div style=" #position: absolute; #top: 50%;display: table-cell; vertical-align: middle;"> <div class="greenBorder" style=" #position: relative; #top: -50%"> any text<br> any height<br> any content,for example generated from DB<br> everything is vertically centered </div> </div> </div>