问题
any idea why when i zoom out website 4div always go down to next line. Demo: http://autovin.org/tp/
/* Reset All Styles */
* {padding:0px; margin:0px;font-family:Segoe UI;}
/* Background */
body {background:url(images/grids.gif) white;}
/* Wrapper */
.wrapper {width:998px;margin:0 auto;}
/* Header */
.header {padding:20px 0 20px 0;}
/* Navigation */
.nav {background:#82b2c9;color:white;}
/* Content */
.content {padding:10px 0;overflow:hidden;}
/* Box */
.box {width:240px; margin:0 10px 10px 0;border:1px solid black;float:left;}
.box:nth-child(4n){margin:0;}
/* Pagination */
.pagination {clear:both;}
/* Footer */
.footer {background:#82b2c9;color:white;}
回答1:
I would just use percentages and em units instead of pixels because browsers are much more compatible with them. But in your case, I don't see people zooming out that far anyways. You want a quick fix, but I suggest rethinking this from the start. Read about box sizing and percentages. Box sizing is super great. Good luck!
http://jsfiddle.net/sheriffderek/xr6nC/
HTML
<ul>
<li><a href="#">Your block of text</a></li>
<li><a href="#">Your block of text</a></li>
<li><a href="#">Your block of text</a></li>
<li><a href="#">Your block of text</a></li>
<li><a href="#">Your block of text</a></li>
<!-- etc. -->
</ul>
</div>
CSS
.container {
width: 100%;
max-width: 40em; /* whatever you want */
border: 1px solid red;
overflow: hidden;
}
.container ul {
padding: 0;
margin: 0;
list-style: none;
}
.container a {
width: 22%; /* this isn't perfect - but it would be 23.5% - if you were to use box-sizing: border-box; */
/* which I highly recomend you make part of your workflow in every project */
float: left;
border: 1px solid black;
min-height: 5em;
margin-right: 2%;
margin-bottom: 2%;
}
.container li a:nth-of-type(4n+4) {
margin-right: 0;
}
来源:https://stackoverflow.com/questions/17818506/when-i-zoom-out-web-4-div-go-down-to-next-line