How to set background image in html that work in I

2019-09-06 18:06发布

问题:

This question already has an answer here:

  • CSS background-size not working in IE7/8 [duplicate] 4 answers

The following css code is not working in internet explorer.. Please suggest me the solution that work in internet explorer to set background

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;
}

回答1:

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 */
}


回答2:

Older version of IE don't support background-size: if you need to use a fall back for older version of IE do this:

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;
}