According to canius (http://caniuse.com/#search=background-size), background-size compatibility is IE9 and above browsers, as shown in the figure below.
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:
(2) IE8 browser:
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='img/aaa.jpg', sizingMethod='scale'); }
IE8 browser effect:
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!