Home  >  Article  >  Web Front-end  >  Example of solution for background-size IE8 compatibility

Example of solution for background-size IE8 compatibility

高洛峰
高洛峰Original
2017-03-21 14:58:143497browse

According to canius (http://caniuse.com/#search=background-size), background-size compatibility is IE9 and above browsers, as shown in the figure below.

解决background-size IE8兼容方案实例

Instance code:

<!doctype html>
<html>

    <head>
        <meta charset="UTF-8" />
        <title>background-size 兼容性处理</title>
        <style type="text/css">
            * {
                margin: 0;
                padding: 0;
            }
            
            .parent {
                width: 400px;
                height: 400px;
                margin: 100px;
                border: 1px solid red;
                background: url(img/aaa.jpg) no-repeat center center;
                background-size: 100% 100%;
            }
        </style>
    </head>

    <body>
        <div>
        </div>
    </body>

</html>

Effect:

(1) Chrome browser:

解决background-size IE8兼容方案实例

(2) IE8 browser:

解决background-size IE8兼容方案实例

Compatibility solution:

Use filter attribute:

.parent {
                width: 400px;
                height: 400px;
                margin: 100px;
                border: 1px solid red;
                background: url(img/aaa.jpg) no-repeat center center;
                background-size: 100% 100%;
                /*下一行为关键设置*/
                filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=&#39;img/aaa.jpg&#39;,  sizingMethod=&#39;scale&#39;);
            }

IE8 browser effect:

解决background-size IE8兼容方案实例

Principle:

filter: progid:DXImageTransform.Microsoft.AlphaImageLoader (enabled=bEnabled, sizingMethod=sSize, src=sURL )

enabled: Optional. Boolean. Sets or retrieves whether the filter is active. true: default value. Filter activated. false: filter is disabled.

sizingMethod: Optional. String. Sets or retrieves how the image of the filtered object is displayed within the boundaries of the object container. crop: Crop the image to fit the object size. image: default value. Increase or decrease the size bounds of the object to fit the dimensions of the picture. scale: Scale the image to fit within the object's size boundaries.

src: Required. String. Specify the background image using an absolute or relative url address. If this parameter is omitted, the filter will have no effect.

The above is the detailed content of Example of solution for background-size IE8 compatibility. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn