固定位置居中不适用于Internet Explorer

时间:2015-02-02 22:26:39

标签: html css

我未能在互联网资源管理器中占据固定位置(在Internet Explorer 11上无效,未在旧版本上测试)我当前的css代码是:

.banner {
position: fixed;
max-width:1180px !important;
z-index:9999;
top: 0px;
background: #000 !important;
left: 0;
right: 0;
}

在mozila firefox和谷歌浏览器上它可以正常工作。

编辑:我已经通过编辑代码解决了这个问题:

 .banner {
    position: fixed;
    width:1180px !important;
    z-index:9999;
    top: 0px;
    background: #000 !important;
    left: 0;
    margin:0 auto;
    right: 0;
    }

2 个答案:

答案 0 :(得分:0)

.banner{
    position: fixed;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
}

对于转换,您必须为每个浏览器添加供应商前缀,但应该可以使用

答案 1 :(得分:-1)

只需使用:

margin: 0 auto;

应该使元素居中。指定left:和right:可能没有效果。

相关问题