有人知道为什么下面的代码不工作吗?我真的很想使用这个方法,而不是任何JavaScript方法。我也试过绝对路径,但运气不好。
.test {
width: 500px; /* Must Specify Width */
height: 176px;
filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale, src='../images/test-bg.png');
}
我认为sizingMethod=scale
应该是sizingMethod="scale"
我看到您已经尝试了绝对路径,但是您是否尝试了来自(不包括)域的路径?
所以如果完整路径是"http://www.example.co.uk/images/test.png"你只需使用"/images/test.png"
这是我过去使用它的方式
尝试:
filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='../images/test-bg.png', sizingMethod=scale, enabled="true");
与CSS文件中的其他文件引用不同,filter
属性的src
属性是相对于浏览器中的URL的。因此,对于您的示例代码,假设图像文件夹在http://www.yoursite.com/images
,您使用的src
是../images/test-bg.png
:
http://www.yoursite.com/ -> Doesn't work
http://www.yoursite.com/some-page/ -> Works
http://www.yoursite.com/some-page/another-level-deeper/ -> Doesn't work
最好的方法是使用相对于根目录的路径,如下所示:
filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/images/test-bg.png',sizingMethod='scale');
如果这不是问题,另一种可能是图像的大小可能太小。在过去,我发现拉伸1x1像素的图像可能会有bug,有时无法正确渲染。在这种情况下,一个解决方法是使用更大的图像(超过5x5像素)。