简体   繁体   English

HTML:div中的垂直对齐div

[英]HTML: Vertical align div in div

I would like to vertical center a div in another div, but I don't get it to work. 我想将一个div垂直居中放置在另一个div中,但无法正常工作。 The image div needs to be centered in the parent (black) div. 图像div需要在父div(黑色)div中居中。 I've already tried the 我已经尝试过

position: absolute;

fix, as well as the 修复,以及

display: table-cell; 

but they both don't seem to work. 但它们似乎都不起作用。 The probleems seems to be my parent div being 100%.. Can anybody help me out? 问题似乎是我的父级div是100%。有人可以帮助我吗? The example is here: 示例在这里:

http://jsfiddle.net/mkGXx/ http://jsfiddle.net/mkGXx/

<div style="display: table; height: 800px; #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 content<br /><br /><br />
        everything is vertically centered
      </div>
    </div>
  </div>

see at: http://jsfiddle.net/9eDXM/ 参见: http : //jsfiddle.net/9eDXM/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM