不定宽度的水平居中,通常我们的居中方式
.box{width:200px;margin:0 auto;}
但是在没有固宽的情况下.居中就麻烦了
不过可以这样写,用relative;
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<div style="width:900px; margin:0 auto; background-color:#999; height:100px;">
<div style="position:relative; background-color:#030; height:50px; left:50%; float:left;">
<div style="position:relative; right:50%; background:#F00;height:25px;">我要居中</div>
</div>
</div>
</body>
</html>
zz: