如何在适用于 Internet Explorer 的 html 中设置背景图像?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19449185/
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
How to set background image in html that work in Internet explorer?
提问by ANILBABU
The following css code is not working in internet explorer.. Please suggest me the solution that work in internet explorer to set background
以下 css 代码在 Internet Explorer 中不起作用.. 请建议我在 Internet Explorer 中设置背景的解决方案
body {
background: url("images/Login-BG.png") no-repeat center center fixed;
-moz-background-size: cover;
-webkit-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
采纳答案by Akshay Khandelwal
For your code to work you need to have height to your body which may be equal to the height of your image.
要使您的代码正常工作,您的身体需要有一个高度,该高度可能等于您的图像的高度。
body {
background: url("images/Login-BG.png") no-repeat center center fixed;
-moz-background-size: cover;
-webkit-background-size: cover;
-o-background-size: cover;
background-size: cover;
height: 265px; /* considering that 265 is the image height */
}
回答by aaronmallen
Older version of IE don't support background-size:
if you need to use a fall back for older version of IE do this:
background-size:
如果您需要为旧版本的 IE 使用回退,则旧版本的 IE不支持,请执行以下操作:
body {
/* ie fallbacks */
background-image: url(images/Login-BG.png);
-ms-filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='images/Login-BG.png', sizingMethod='scale')";
/* desired styles */
background: url("images/Login-BG.png") no-repeat center center fixed;
-moz-background-size: cover;
-webkit-background-size: cover;
-o-background-size: cover;
background-size: cover;
}