【发布时间】:2014-11-18 13:57:28
【问题描述】:
我试图保持主 div 始终居中,但是当将浏览器窗口的大小调整为从 900 像素开始的最小尺寸时,我怎样才能使“主”保持在左侧,并且只有在更大的屏幕或 900 像素以上时,他才开始居中页面在中间?
提前致谢
CSS:
body {
font: 24px Helvetica;
background: #999999;
min-width: 900px;
margin: 0;
}
#main {
margin-left: auto;
margin-right: auto;
clear: both;
}
header {
width: 100%;
background: yellow;
text-align: center;
}
nav {
width: 20%;
min-width: 120px;
max-width: 300px;
float: left;
height: 600px;
background: orange;
text-align: center;
}
article {
width: 80%;
min-width: 400px;
max-width: 1200px;
float: left;
height: 600px;
background: yellow;
text-align: center;
}
footer {
width: 100%;
float: left;
height: 100px;
background: blue;
text-align: center;
}
HTML:
<header>header</header>
<div id='main'>
<nav>nav</nav>
<article>article</article>
</div>
<footer>footer</footer>
【问题讨论】:
-
考虑在媒体查询中寻找类似的东西。 w3schools.com/cssref/css3_pr_mediaquery.asp