简体   繁体   中英

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. The image div needs to be centered in the parent (black) 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? The example is here:

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/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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