IE8 fix for background-size property? Retina Image

前端 未结 1 759
[愿得一人]
[愿得一人] 2020-12-24 10:00

I am using the following CSS for Retina images and it works perfectly in FF, Chrome, Safari but not in IE.

Is there a fix for IE for using backgroun

相关标签:
1条回答
  • 2020-12-24 10:35

    IE8 and below simply don't support background-size so you're either going to have to use the AlphaImageLoader Filter which has been supported since IE5.5:

    .arrow-big-right {
        display: block;
        width: 42px;
        height: 48px;
        margin-bottom: 1.8em;
        background-image: url(arrow-big-right.png);
        background-repeat: no-repeat;
        background-size: 42px 48px;
        filter: progid:DXImageTransform.Microsoft.AlphaImageLoader( src='arrow-big-right.png', sizingMethod='scale');
        -ms-filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader( src='arrow-big-right.png', sizingMethod='scale')";
    }
    

    Or use some method of targeting IE versions via CSS to apply an alternative to your background for IE8 and below users.

    It's also worth noting, as Matt McDonald points out, that you may see two images as a result of using this technique. This is caused by the IE filter adding a background image in addition to, instead of replacing, the standard background image. To resolve this, target IE via css using your preferred method (here's a method, my personal favourite) and remove the standard background-image for IE8 and below.

    Using the first technique from Paul Irish's blog post to do this, you could use the following:

    .arrow-big-right {
        display: block;
        width: 42px;
        height: 48px;
        margin-bottom: 1.8em;
        background-image: url(arrow-big-right.png);
        background-repeat: no-repeat;
        background-size: 42px 48px;
        filter: progid:DXImageTransform.Microsoft.AlphaImageLoader( src='arrow-big-right.png', sizingMethod='scale');
        -ms-filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader( src='arrow-big-right.png', sizingMethod='scale')";
    }
    
    .ie6 .arrow-big-right, 
    .ie7 .arrow-big-right, 
    .ie8 .arrow-big-right {
        background-image: none;
    }
    
    0 讨论(0)
提交回复
热议问题