IE 10,当我单击“兼容性”按钮时,所有内容都会移至左侧

2023-12-27

问题是当我单击兼容性按钮或在开发人员工具中尝试在 IE 7,8 或 9 中查看页面时

当我单击 IE 10 中的兼容性按钮(URL 区域旁边)时,页面上的所有控件都会向左浮动。

不知道出了什么问题,我还尝试了 IE 9、8 和 7 的浏览器模式,但一切仍然位于左侧。

我还注意到,一旦刷新页面(在兼容模式下)一切都会正常。

<div id="outer">
    <div id="inner">
        <div id="content">
            <div id="header">
                <div id="headertext">
                    <div>SomeeeeeeeeText</div>
                    <div class="bp">SomeTexttttttttttttttttttttttt</div>
                </div>
            </div>
        </div>
    </div>
</div>

and

CSS

body {
    font-family: 'Segoe UI', Segoe, Tahoma, Helvetica, Arial, sans-serif;
    text-align: left;
    background-color: #0783FF;
    color: #fff;    
}

#outer {
    display: table;
    height: 100%;
    width: 100%;
}

#inner {
    display: table-cell;
    vertical-align: middle;
}

#content {
    width: 65%;
    margin-left: auto;
    margin-right: auto;
}

#header {
    text-align: center;
    color: #fff;
}

#header>img, #headertext {
    display: inline-block;
}

#headertext {
    text-align: left;
}

#headertext .bp {
    font-size: 2.6em;
    line-height: 0.8em;
}

Updating

这是一个小提琴 http://jsfiddle.net/6wGnV/


您的布局使用了相对现代的 CSS 功能,例如display: table and display: table-cell。从 IE8 开始才支持这些。

然而,“兼容模式”经常会将Internet Explorer切换到Quirks模式,这基本上就是IE5.5模式。我怀疑display: table and display: table-cell在这里不起作用:它们是在 IE5.5 发布后发明的。

所以实际上,你有两个选择:

  1. 将您的文档类型更改为 HTML5 (<!DOCTYPE html>) 或 HTML 4.01 严格 (<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">)并在标准模式下渲染。我建议这样做。

  2. 更改您的 CSS 以使用 IE5.5 中提供的技术。基本上,这意味着使用float用于布局和与盒子模型的战斗(IE和其他浏览器的宽度计算方式不同)。

Edit:

如果(从评论中推断出你的其他问题之一 https://stackoverflow.com/questions/23133939/document-mode-in-ie-10)你想要垂直居中#content框,尝试设置html, body { height: 100%; }。在标准模式下,height: 100%;表示父元素高度的 100%。如果 html 和/或 body 仅与内容一样高,则它不会在屏幕上垂直居中。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

IE 10,当我单击“兼容性”按钮时,所有内容都会移至左侧 的相关文章