有没有已知的方法可以使CSS样式background-size
在IE中工作?
有没有已知的方法可以使CSS样式background-size
在IE中工作?
有点晚了,但这也可能是有用的。有一个IE过滤器适用于IE 5.5+,可以应用它:
filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(
src='images/logo.gif',
sizingMethod='scale');
-ms-filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader(
src='images/logo.gif',
sizingMethod='scale')";
然而,这会将整个图像缩放以适应分配的区域,因此,如果您正在使用精灵图,这可能会导致问题。
body
或html
元素,则该属性可能会破坏滚动、链接和其他页面交互。 - SouthShoreAK我创建了jquery.backgroundSize.js,这是一个1.5K的jQuery插件,可用作IE8中“cover”和“contain”值的备选方案。请查看演示。
background-position: fixed
。 - Ryan Burney多亏了这篇文章,我现在拥有了跨浏览器兼容的完整CSS:
<style>
.backgroundpic {
background-image: url('img/home.jpg');
background-size: cover;
filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(
src='img/home.jpg',
sizingMethod='scale');
}
</style>
虽然我已经很久没有处理这段代码了,但我想为了更好的浏览器兼容性,在我的CSS文件末尾添加了以下内容:
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
-webkit-background-size: cover; -moz-background-size: cover; -o-background-size: cover; background-size: cover;
。 - honk31有一个很好的polyfill可用于此:louisremi/background-size-polyfill
引用文档:
Upload backgroundsize.min.htc to your website, along with the .htaccess that will send the mime-type required by IE (Apache only — it's built in nginx, node and IIS).
Everywhere you use background-size in your CSS, add a reference to this file.
.selector { background-size: cover; /* The url is relative to the document, not to the css file! */ /* Prefer absolute urls to avoid confusion. */ -ms-behavior: url(/backgroundsize.min.htc); }
contain
和cover
。它包含5.7KB,因为它可以在一个网络数据包中传输,所以并不算太糟糕。 - S.M.Mousavi在IE11 Windows 7中,以下方法对我有效:
background-size: 100% 100%;
.selector {
background-image: url("img/image.jpg");
background-size: 100%;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-repeat: no-repeat;
}
它对我有用!
你可以使用这个文件(https://github.com/louisremi/background-size-polyfill “background-size polyfill”)来解决IE8中的背景大小问题,它非常简单易用:
.selector {
background-size: cover;
-ms-behavior: url(/backgroundsize.min.htc);
}