现在用DIV来定位的方式使用得越来越广泛,在使用DIV定位图片的时候,发现DIV不能直接设置图片的垂直对齐方式.
有一个解决方法看起来很正宗。如下
<div id="Layer1"
style="position:absolute;
width:500px;
height:305px;
z-index:1;
background-color: #999999;
border: 1px none #000000;
padding-top:expression(this.style.top+(this.offsetHeight-mxh.offsetHeight)/2)"
align=center >
<img src="/help/UploadFiles_4256/200806/20080611155246678.gif" id=mxh>
</div>
但在使用了以后发现还是不能成功,其实在这个方法里面有两个问题:
依据以上两点,对上面的代码进行了修改,得到下面的这个方法:
<div id="Layer1"
style="
position:absolute;
left:261px;
top:50px;
width:251px;
height:105px;
z-index:1;
overflow:hidden;
border: 1px solid #0066CC;
padding-top:expression((this.offsetHeight-myImage.offsetHeight)/2);
"
align="center">
<img src="12.gif" width="70" height="76" align="absmiddle" id="myImage">
</div>

附:有一个关键点提醒大家注意一下,图片要给出ID,才能进行计算