时间:2021-07-01 10:21:17 帮助过:201人阅读
实例代码:
- <!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>
效果:
(1)chrome浏览器:
(2)IE8浏览器:
使用filter属性:
- .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浏览器效果:
filter : progid:DXImageTransform.Microsoft.AlphaImageLoader ( enabled=bEnabled , sizingMethod=sSize , src=sURL )
enabled:可选项。布尔值(Boolean)。设置或检索滤镜是否激活。 true:默认值。滤镜激活。 false:滤镜被禁止。
sizingMethod:可选项。字符串(String)。设置或检索滤镜作用的对象的图片在对象容器边界内的显示方式。 crop:剪切图片以适应对象尺寸。 image:默认值。增大或减小对象的尺寸边界以适应图片的尺寸。 scale:缩放图片以适应对象的尺寸边界。
src:必选项。字符串(String)。使用绝对或相对 url 地址指定背景图像。假如忽略此参数,滤镜将不会作用。
以上就是解决background-size IE8兼容方案实例的详细内容,更多请关注Gxl网其它相关文章!