When i Zoom out web 4 div go down to next line

会有一股神秘感。 提交于 2019-12-13 04:37:54

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!