CSS div : margin:auto on vertical for IE7

标签 css html

<div id="wr">
    <div id="unknownWidthAndHeight">should be centered on both sides</div>
</div>

#wr {
    display:table-cell;
    width:400px;
    height:100px;
    border:1px solid red;
    margin:50px;
    vertical-align:middle;
}
#unknownWidthAndHeight{
    display:table;
    height:30px;
    margin:auto;    
    border:1px solid blue;
}

这是 fiddle 的例子: http://jsfiddle.net/gdTGZ/2/

在没有 display:table 的情况下需要对 IE7 的支持等等,没有 <table>用法。

最佳答案

1/如果你想在 IE7 上垂直居中试试这个使用三个 div 的技术: http://www.jakpsatweb.cz/css/css-vertical-center-solution.html

注意:您始终需要设置容器高度

2/你想要水平居中的元素必须有一个widthmargin:0 auto;否则你可以试试文本对齐:居中

关于CSS div : margin:auto on vertical for IE7,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8605586/

相关文章:

jquery - 根据单击的链接使用 jquery 编辑 div

html - Bootstrap 分页控件的对齐方式相同

css - CSS 中的内容属性

css - 使用 :not 从样式中排除 child

javascript - JQuery Lightbox - 对不是链接的图像进行分组

jQuery 悬停功能,无法按预期使用段落标签

javascript - 点击隐藏文件输入jQuery报错

javascript - 使用 JavaScript 中的正则表达式从 anchor 标记字符串中提取内部文本

javascript - 圆形按钮的制作方法

javascript - 查询 : Increase animation speed during animation