水平垂直居中问题

<div style="background:blue;position:absolute;left:expression((body.clientWidth-50)/2);top:expression((body.clientHeight-50)/2);width:50;height:50"></div>

如果固定高度和宽度,则:left:(x-width)/2 top:(y-height)/2   或者

left:50%; margin-left:-width/2;

 

<body bgcolor="#000000">
<div style="background:cyan;position:absolute;left:expression((body.clientWidth-250)/2);top:expression((body.clientHeight-250)/2);width:250;height:250"></div>
<div style="background:yellow;position:absolute;left:expression((body.clientWidth-200)/2);top:expression((body.clientHeight-200)/2);width:200;height:200"></div>
<div style="background:red;position:absolute;left:expression((body.clientWidth-150)/2);top:expression((body.clientHeight-150)/2);width:150;height:150"></div>
<div style="background:green;position:absolute;left:expression((body.clientWidth-100)/2);top:expression((body.clientHeight-100)/2);width:100;height:100"></div>
<div style="background:blue;position:absolute;left:expression((body.clientWidth-50)/2);top:expression((body.clientHeight-50)/2);width:50;height:50"><center><img src=""></div>

你可能感兴趣的:(div)