Html 保证金自动失败 IE11
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31784147/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Margin auto fails IE11
提问by Funny Frontend
if you check my websitewith the browser Chrome you can see how the div called .bg-content works fine with this style:
如果您使用 Chrome 浏览器查看我的网站,您会看到名为 .bg-content 的 div 是如何在这种样式下正常工作的:
.bg-content {
max-width: 605px;
height: 149px;
position: absolute;
top: 62px;
font-family: sans-serif;
margin-left: auto;
margin-right: auto;
left: 0;
right: 0;
}
But if you open my website with Internet Explorer 11 the div .bg-content is not centered, he is floating to left.
但是,如果您使用 Internet Explorer 11 打开我的网站,则 div .bg-content 未居中,他向左浮动。
How can I fix this?
我怎样才能解决这个问题?
回答by cgee
it doesn't work because the max-width;
它不起作用,因为最大宽度;
Try this:
尝试这个:
.bg-content {
width: 605px;
height: 149px;
position: absolute;
top: 62px;
font-family: sans-serif;
margin-left: auto;
margin-right: auto;
left: 0;
right: 0;
}
回答by Xyv
The hack I always use for Internet Explorer (mostly for the older versions though), is setting the parent container text-align: center;
and the container itself text-align: left;
.
我总是在 Internet Explorer 上使用的 hack(尽管主要用于旧版本)是设置父容器text-align: center;
和容器本身text-align: left;
。
I have taken a look at your website, and the parent container seems to not have a default width. Please try setting it on width: 100%;
. I tried that in the run-time environment, and it seemed to work.
我查看了您的网站,父容器似乎没有默认宽度。请尝试将其设置为width: 100%;
。我在运行时环境中尝试过,它似乎有效。
回答by Alexandre Canijo
You should use
你应该使用
width: 100%;
width: 100%;
in your .bg-content element
在您的 .bg-content 元素中
Example: IE11 max-width & margin auto fix
示例: IE11 最大宽度和边距自动修复
回答by Tristanisginger
for a fixed position element :
对于固定位置元素:
left: 0;
right: 0:
width: 100%;
margin: 0 auto;
回答by Hadnazzar
For absolute position element you can use this
对于绝对位置元素,您可以使用它
position: absolute;
margin: 0 auto;
left: 0;
right: 0;
top: 200px; // change this as you want
width: 450px; // change this as you want
margin-left: auto;
margin-right: auto;