CSS vertical-align:middle not working in IE7

。_饼干妹妹 提交于 2019-12-06 05:01:08

I hope it will help to resolve your issue(Some cheats for IE 7 in the bottom of the article)

Vertically Center Multi-Lined Text

For Example code like this

margin-top: expression((parentNode.offsetHeight.offsetHeight/2)-(parseInt(this.offsetHeight)/2) <0 ? "0" :(parentNode.offsetHeight/2)-(parseInt(this.offsetHeight)/2) +'px');

instead of

 vertical-align:middle;
  1. parentNode.offsetHeight/2 - determines the container's height and divide it by 2. This gives us a margin exactly half the height of the screen
  2. -(parseInt(offsetHeight)/2)) - determines the height of the centering block.

Since you know the height of the div (you are specifying it at 200px), you can fix it like this:

.container{
    position:relative;
}
.v-middle{
    position:absolute;
    top:50%;
    margin-top:-100px;
}

HTML:

<div class="pics2">

<div class="container" style="position: absolute; top: 0px; left: 0px; display: block; z-index: 4; opacity: 1; width: 225px; height: 200px;"> // this div is generated via jQuery Plugin
<div class="v-middle" style="display:table-cell; vertical-align:middle; height:200px;">
<img src="upload/<?php echo $array['image5'] ?>" width="225" />
</div>
</div>

Edit: Here is a working example: http://jsfiddle.net/MUrbL/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!