如我们希望wrap元素长度随窗口而改变,同时又维持居中,我们就可以这样写: body {
padding:10px 150px;
}
这里,我们只需要保持父元素左右两侧的填充是相等的就可以了。
<!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>
<title> 随浏览器窗口大小而改变的具有弹性的居中布局 </title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<style type="text/css">
body {
padding:10px 150px;
}
div#wrap {
border:1px solid #333;
background-color:#ccc;
}
</style>
</head>
<body>
<div id="wrap">
一种随浏览器窗口大小而改变的具有弹性的居中布局:
<pre>
body {
padding:10px 150px;
}
这里,我们只需要保持父元素左右两侧的填充是相等的就可以了。
</pre>
</div>
</body>
</html>
当然这只是“貌似居中”,不过却常常很有用处。










