简体   繁体   English

为什么我重复的PNG背景图片在IE7或IE8中不显示?

[英]Why does my repeated PNG background image not show in IE7 or IE8?

I am trying to convert a PSD to HTML and I am facing a problem. 我正在尝试将PSD转换为HTML,但遇到了问题。 My site works in all major browsers except IE8 and IE7. 我的网站可以在除IE8和IE7之外的所有主要浏览器中使用。 The background is not showing at IE8 and IE7. IE8和IE7上没有显示背景。

The background is a PNG image and it is repeated. 背景是PNG图像,并且会重复。 I know the way for non-repeated images but for repeated images what do I need to do? 我知道处理非重复图像的方法,但是对于重复图像,我该怎么办? Here is the CSS that I have used: 这是我使用的CSS:

#footer-top {
    padding: 20px 0;
    background: url('img/footer-bg.png')repeat;
    width:100%;
    overflow:hidden;
    margin-top: 38px;
}

See the blog post PNG background-repeat bug in Internet Explorer 7 and 8 请参阅Internet Explorer 7和8中的博客文章PNG背景重复错误

It says: 它说:

Apparently Internet Explorer 7 and 8 still haven't gotten PNG quite right. 显然,Internet Explorer 7和8尚未完全正确使用PNG。 While working on one of my current projects, I stumbled onto a bug with repeating PNG background images. 在执行我当前的项目之一时,我偶然发现了一个重复PNG背景图像的错误。

For this project, I have a page template with several container elements that all have a 1 pixel by 1 pixel PNG background set to repeat, and it looks great when testing it in IE 7 and IE 8. So, I created my next page template with the same styling. 对于这个项目,我有一个页面模板,其中包含多个容器元素,所有容器元素都具有重复设置为1像素乘1像素的PNG背景,并且在IE 7和IE 8中进行测试时看起来很棒。因此,我创建了下一个页面模板具有相同的样式。 This time, IE 7 and 8 both choked when handling the background-repeat. 这次,IE 7和IE 8在处理后台重复时均被阻塞。 Instead of repeating, both of these browsers inexplicably tried to stretch the 1×1 image across the entire container. 这两个浏览器都没有重复说明,而是莫名其妙地尝试在整个容器中拉伸1×1图像。 The PNG happened to have 60 percent alpha transparency, but I'm not sure that matters. PNG碰巧具有60%的Alpha透明度,但我不确定这很重要。 A coworker suggested making it a 10×10 pixel image instead, just to see what happens. 一位同事建议改为将其制作为10×10像素的图像,以查看会发生什么。 Surprise, surprise. 惊喜,惊喜。 That fixed it. 这样就解决了。

I did a little more searching to see if anyone else had come across this and found this recent blog post. 我做了更多的搜索,看看是否有人遇到过这个问题,并找到了这篇最近的博客文章。 The author also found that this bug appears to occur at random, and that a 4×4 pixel image solved his problem. 作者还发现该错误似乎是随机发生的,并且4×4像素的图像解决了他的问题。 Since there's no very little file size difference between 10×10 and 1×1, I'll stick with the 10×10. 由于10×10和1×1之间的文件大小差异很小,因此我坚持使用10×10。 But I agree with him that this bug created a cool effect, and it would be great if it could be replicated at will. 但是我同意他的观点,这个错误产生了很酷的效果,如果可以随意复制它会很棒。

Maybe you need a space before repeat ? 也许您需要空格才能repeat

background: url('img/footer-bg.png') repeat;

(I don't have IE7 or 8 handy to check this.) (我没有IE7或8方便查看。)

I dear , I have find the easiest way . 亲爱的,我找到了最简单的方法。 Just try it 去尝试一下

background-image:url(images/back-bg.jpg) !important;
background-repeat:repeat !important;
background-color:#fff !important;
background-position:left !important;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM