位置:固定边距:IE9 / 10自动

时间:2014-08-19 17:17:26

标签: css internet-explorer css-position

我为响应式网站制作了一个粘性标题,其中标题也以margin: 0 auto为中心。它适用于Chrome / Firefox / Safari / IE8,但不适用于IE9 +。

最小标记:

<div class="viewport">
    <header class="banner">
    </header>
</div>

风格:

.banner {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    width: 100%;
    max-width: 1024px;
    margin: 0 auto;
}

在IE9 +中,标题卡在左侧。

1 个答案:

答案 0 :(得分:6)

您需要专门为相关元素添加width: 100%

<强> Demo

enter image description here

CSS

.banner {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    width: 100%;
    max-width: 750px;
    margin: 0 auto;
    background: red;
    height: 50px;
}

实际上它在IE9中同样运行良好

enter image description here