css - 在 Div Box 中居中 Div 框

标签 css html alignment center

我已将页脚添加到 EasyCareBath.com ,我可以让 div 正常工作,除了“.footer_box”,它不会居中。我添加了“left: 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;
}

最佳答案

将您的 .footer_box 规则更改为:

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

margin: 0 auto; 使 footer_box 居中。

position: relative; 使您的绝对定位列基于 footer_box 而不是主体定位。

旁注/我一直喜欢的类比: 将“自动”想象成将橡皮筋连接到与页面边缘相连的元素的那一侧......在这种情况下,“自动”位于右侧和左侧,所以 - 如果有橡皮筋拉动无论屏幕大小如何,它始终居中。

关于css - 在 Div Box 中居中 Div 框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13400650/

相关文章:

javascript - 使 CSS 菜单项加载网站而不是使用 javascript 更改占位符

php - 在 PHP 中对齐表单

javascript 隐藏切换使用一个类,还是直接隐藏?

java - 如何将 HTML 文件显示为网页?

html - Bootstrap CSS 弄乱图像(边框图像)

java - 修改 JTable 单元格中的文本对齐方式

html - CSS 使整个相对主体水平居中,无需包装器或滚动条?

html - 在鼠标悬停时旋转一个 div 并在鼠标移开时继续

html - 限制 div 以仅获取特定样式表

css - Div 向左浮动 : Long divs clearing?