绝对定位适用于全宽页面,但是当您有一个居中的固定宽度时呢?提出了一个基于 flex-box 的解决方案,适用于 IE8+。flexie polyfill 用于旧版浏览器
见http://jsfiddle.net/lorantd/9GFwT/10/
<div id="header"></div>
<div id="main">
<div id="menu"></div>
<div id="content"></div>
<div id="summary"></div>
</div>
<div id="footer"></div>
#header {
background-color: #9B9EA7;
height: 70px;
}
body {
min-width: 500px;
max-width: 630px;
margin-right: auto;
margin-left: auto;
display: block;
}
#main {
display: -moz-box; /* OLD - Firefox 19- (buggy but mostly works) */
display: -ms-flexbox; /* TWEENER - IE 10 */
display: -webkit-flex; /* NEW - Chrome */
display: flex; /* NEW, Spec - Opera 12.1, Firefox 20+ */
display:-webkit-box; /* Safari and Chrome */
display:box;
width: 100%;
}
#menu {
background-color: #D42108;
width: 120px;
margin-top: 10px;
margin-right: 10px;
}
#content {
background-color: #FFD700;
height: 500px;
margin-top: 10px;
margin-right: 10px;
-webkit-box-flex: 2; /* OLD - iOS 6-, Safari 3.1-6 */
-moz-box-flex: 2; /* OLD - Firefox 19- */
width: 60%; /* For old syntax, otherwise collapses. */
-webkit-flex: 2; /* Chrome */
-ms-flex: 2; /* IE 10 */
flex: 2;
}
#summary {
width: 30px;
margin-top: 10px;
background-color: #9B9EA7;
}
#footer {
background-color: #353535;
width: 100%;
height: 50px;
margin-top: 10px;
clear: both;
}