0

我已将页脚添加到EasyCareBath.com,我可以让 div 正常工作,除了“.footer_box”,它不会居中。我添加了“左:15%”,当你把窗户炸开时,它不再对齐。我错过了什么还是我对 CSS 做了太多?

.footer_spacer {
    height: 50px;   
}
.footer_wrapper {
    height: 375px;
    background-color: #e6dccb;
}
.footer {
    border-top: 10px solid #789E65;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.6);
    margin-top: 0px;
    /*min-width: 1007px;*/
    height: 235px;
    background-attachment: scroll;
    background-image: url(../images_footer/footer_bg.png);
    background-repeat: repeat-x;
    background-position: center top;
    position: relative;
}
.footer_box {
    height: 236px;
    width: 1007px;
    /*position: relative;*/
}
.footer_copyright {
    width: 100%;
    /* [disabled]height: 100px; */
    /*float: left;*/
    padding-top: 15px;
    position: relative;
    text-align: center;
    word-spacing: normal;
    font-family: Arial, Helvetica, sans-serif;
    font-size: 14px;
    font-weight: 100;
    font-variant: normal;
    text-transform: none;
    color: #354245;
}
#footer_col_01 {
    position:absolute;
    left:11px;
    top:3px;
    width:164px;
    /*height:230px;*/
    z-index:1;
}
#footer_col_02 {
    position:absolute;
    left:186px;
    top:3px;
    width:164px;
    /*height:230px;*/
    z-index:1;
}
#footer_col_03 {
    position:absolute;
    left:361px;
    top:3px;
    width:164px;
    /*height:230px;*/
    z-index:1;
}
#footer_col_04 {
    position:absolute;
    left:535px;
    top:3px;
    width:183px;
    /*height:230px;*/
    z-index:1;
}
#footer_col_05 {
    position:absolute;
    left:728px;
    top:3px;
    width:265px;
    /*height:230px;*/
    z-index:1;
    font-size: 14px;
}
footer {
    font-family: Arial, Helvetica, sans-serif;
    color: #fff;
    font-size: 11px;
    float: left;
    width: 100%;
}
footer a {
    color: #FFF;
    text-decoration: none;
}
footer a:hover {
    color: #FFF;
    text-decoration: underline;
}
footer h6 {
    font-family: Arial, Helvetica, sans-serif;
    font-size: 16px;
    font-weight: 500;
    color: #00A1CC;
    line-height: 46px;
    /*margin-bottom: -2px;*/
}
footer li {
    line-height: 18px;
    list-style-type: none;
    margin-left: 12px;
}
.footer_img_center {
    text-align: center;
}
4

3 回答 3

5

Alter your .footer_box rule to this:

.footer_box {
    height: 236px;
    width: 1007px;
    margin: 0 auto;
    position: relative;
    }

The margin: 0 auto; centers the footer_box.

The position: relative; makes it so your absolutely positioned columns are positioned based on the footer_box instead of the body.

Side note / an analogy I've always liked: Think of the 'auto' as attaching a rubber band to that side of the item connected to the edge of the page... in this case, 'auto' is on the right AND the left, so - if there's a rubber band pulling from both left AND right, it will always center, regardless of screen size.

于 2012-11-15T15:30:29.130 回答
1

Fix your css as following:

.footer_box {
    height: 236px;
    margin: 0 auto;
    position: relative;
    width: 1007px;
}
于 2012-11-15T15:30:48.430 回答
1

你走在正确的轨道上:

.footer_box {
    height: 236px;
    width: 1007px;
    position: relative;
    margin: 0px auto;
}

无论屏幕大小如何,左右两侧的自动边距将确保页脚始终居中。

于 2012-11-15T15:32:19.487 回答