Example of solution for background-size IE8 compatibility

高洛峰
Release: 2017-03-21 14:58:14
Original
3534 people have browsed it

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>
Copy after login

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;);
            }
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!