如何在调整窗口大小时防止页边距在HTML / CSS代码中扩展

时间:2012-05-16 15:16:37

标签: css layout

我有网站,其周围有15个像素的黑色边距,如图所示

enter image description here

问题在于,当我在宽度方面扩展浏览器窗口时,这个差距变得更大,如下所示

enter image description here

我已经尝试了一段时间使这个宽度保持在15像素,但我无法弄清楚问题是什么。我已经使用了FireBug提供的所有工具,但无济于事。有没有人对我的尝试有任何建议?

通过消除过程,我已经能够缩小此CSS中的错误

/*----------------------------------------------------------------------*/
/* Login
/*----------------------------------------------------------------------*/

body#login{
    position:static;
    left:auto;
    right:auto;
    width:350px;
    margin:120px auto;
    padding:2%;
}
body#login #content{
    min-height:50px;
    padding:8px;
}
body#login form label{
    padding:0;
    margin:0;
    width:100%;
}
body#login form section{
    width:100%;
}
body#login form section div{
    width:90%;
    float:none;
    padding:0 4% 6px 4%;
    border:0;
}
body#login form section > div{
    width:90% !important;
}
body#login form section div input{
    width:100% !important;
}
body#login form section div input#remember{
    width:auto !important;
}
body#login form section div.checker{
    width:auto !important;
    padding:0;
    margin:0;
}
body#login form section label{
    padding:3% 2% 1%;
    width:90% !important;
    float:none;
}
body#login form section label.checkbox div{
    width:10px;
    padding:0;
    margin:0;
}
body#login form section a{
    float:right;
}

/*----------------------------------------------------------------------*/
/* Wizard
/*----------------------------------------------------------------------*/

body#wizard{
    position:static;
    left:auto;
    right:auto;
    width:500px;
    margin:120px auto;
    padding:0;
}
body#wizard #content{
    min-height:50px;
    padding:8px;
}


/*----------------------------------------------------------------------*/
/* Media Queries
/*----------------------------------------------------------------------*/

/* For very large screens increes the margins*/
@media screen and (min-width:1281px) {
body{
    margin-left:10%;
    margin-right:10%;
}
}

/* Move the Headernav to a drop down menu to the right */
@media screen and (max-width:960px) {
#header ul#headernav li ul, #header ul#headernav li ul.collapsed{
    display:none;
}
#header ul#headernav li ul.shown{
    display:block !important;
}
#header ul#headernav{
    border-left:1px solid;
    position:relative;
    float:right;
    height:60px;
    width:60px;
    cursor:pointer;
    background-repeat:no-repeat;
    background-position:center center;
}

#header ul#headernav li ul{
    position:absolute;
    right:0;
    width:170px;
    padding:0;
    margin:0;
    top:60px;
}
#header ul#headernav li ul li{
    float:none;
    margin:0;
    border-bottom:0;
    border-top:0;

}
#header ul#headernav li ul li a{
    padding:10px;   
}
#header ul#headernav li ul li:last-child{
    border-bottom:1px solid;

}
#header ul#headernav li ul span{
    right:5px;
    top:10px;
}
#header ul#headernav li ul li ul{
    position:relative;
    top:0;
    padding:0;
    display:none;
    padding-bottom:6%;
    z-index:20;
    width:99%;
}
#header ul#headernav li ul li ul.shown{
    display:block;
}
#header ul#headernav li ul li ul li{
    margin:0 6%;
}
#header ul#headernav li ul li ul li a{
    font-size:12px;
    padding:5px;
}

.g1,.g2,.g3,.g4,.g5,.g6 {
    padding:0;
    width:48.0%;
}
.g7,.g8,.g9,.g10,.g11,.g12 {
    padding:0;
    width:98%;
}
}
@media screen and (max-width:900px) and (min-width:701px) {
    form fieldset > section > div{
        width:69%;
    }
    form fieldset > section label{
        width:24%;
    }
}

/* For more smaller Screens (iPad) */
@media screen and (max-width:700px) {
    header #search,header #searchbox{
        max-width:100px;
    }
    form label{
        padding:10px 1%;
    }
    form fieldset > section{
        padding-bottom:8px;
    }
    form fieldset > section > label{
        left:0;
        right:0;
        width:98%;
        margin:0;
        float:none;
        padding:1%;
        padding-bottom:8px;
    }
    form fieldset > section > div{
        float:none;
        width:98%;
        padding:4px;
        border:0;
    }
    .g1,.g2,.g3,.g4,.g5,.g6,.g7,.g8,.g9,.g10,.g11,.g12 {
        width:98%;
    }
}
@media screen and (max-width:800px) and (min-width:481px) {
    nav{
        width:150px;
    }
    nav ul li a span{
        font-size:12px;
    }
    nav ul li ul{
        margin-left:10px;
        margin-right:10px;
    }
    nav ul li ul li a span{
        padding-right:4px;
    }
    #content{
        padding:15px 0 15px 160px;
    }

    #header ul li ul li,#header ul li ul li a, #header ul#headernav li ul li ul{
        -webkit-border-radius:0; -moz-border-radius:0; border-radius:0;
    }

    #header ul li ul li:last-child,#header ul li ul li:last-child a{
        -webkit-border-bottom-left-radius:4px; -moz-border-radius-bottomleft:4px; border-bottom-left-radius:4px;
    }

}

/* iPhone and real small devicces */
@media screen and (max-width:480px) {
    body#login{
        position:static;
        left:auto;
        right:auto;
        width:96%;
        margin:10px auto;
        padding:0;
    }
    body#login #content{
        padding:0;
        padding-top:20px;
        width:99%;
    }
    body#login form{
        border:0;
    }
    body#login form section label{
        border:0;
    }
    body#login fieldset{
        margin:0px;
    }
    body#login form > section a{
        margin:10px 4%;
        float:left;
    }
    #pageoptions > div{
        left:2px;
        right:2px;
        padding:15px;
    }
    header #searchbox{
        display:none;
        max-width:40px;
    }
    header #searchbox input{
        max-width:40px;
    }
    body{
        width:96%;
        margin:1%;
    }
    body, header, nav, #content{
        -webkit-box-shadow:none;
        -moz-box-shadow:none;
        box-shadow:none;
    }
    #header{
    }
    #logo{
        width:100%;
    }
    #logo, header, #content{
        width:100%;
    }
    nav, nav ul, nav ul li, nav ul li a, nav ul li a span, nav ul li a:active span, nav ul li a.active span{
        margin:0;
        padding:0;
    }
    nav ul li a:active span, nav ul li a.active span{
        border-top:1px solid;
        background-position:center center;
    }
    nav{
        border-top:1px solid;
        position:static;
        width:98%;
        margin:0 1%;
    }
    nav ul li{
        width:44px;
        display:inline-block;
        margin-left:-2px;
        margin-right:-2px;
    }
    nav ul li a span{
        border-left:1px solid;
        border-bottom:0;
        height:40px;
        text-indent:-9999px;
        background-position:center center;
    }
    nav ul li:first-child a span{
        border-left:0;
    }
    nav ul li ul{
        position:absolute;
        left:0;
        margin:0;
        z-index:15;
        background:none;
        width:98%;
        margin:0 1%;
    }
    nav ul li ul li{
        display:block;
        width:100%;
    }
    nav ul li ul li a span{
        height:20px;
        text-indent:0;
    }

    #content{
        padding:0;
    }
    form{
        padding:0;
        margin:0;
    }
    form input, form textarea{
        font-size:14px;
        max-width:96%;
    }
    #wl_msg{
        right:5px;
        left:5px;
        width:auto;
    }
    .g1,.g2,.g3,.g4,.g5,.g6,.g7,.g8,.g9,.g10,.g11,.g12 {
        width:100%;
        margin:0;
    }
}

有人能发现问题吗?

感谢。

萨钦

2 个答案:

答案 0 :(得分:2)

尝试设置最大宽度适当度,并将溢出隐藏到您的黑色背景中。 我希望这会有所帮助。

FerchoJ

答案 1 :(得分:0)

问题出在这里

/* For very large screens increes the margins*/
@media screen and (min-width:1281px) {
body{
    margin-left:10%;
    margin-right:10%;
}
}