Html CSS 背景图像未在 IE 中显示

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7550592/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 10:47:53  来源:igfitidea点击:

CSS Background Image Not Showing in IE

htmlcssinternet-explorer

提问by JBL

Please help,

请帮忙,

The background image is not showing in IE, but everything is perfectly fine in safari.

背景图像未在 IE 中显示,但在 safari 中一切正常。

I have checked with W3C CSS validation and html validation, everything is ok.

我已经检查过 W3C CSS 验证和 html 验证,一切正常。

What is the problem?

问题是什么?

http://www.applezone.com.hk/newrx/

http://www.applezone.com.hk/newrx/

body
{ 
/*background-color:#eee;*/
font-family:Arial, Helvetica, sans-serif;
margin: 0px 0px 0px 0px;
background:url(images/bg_line.JPG);
background-repeat:repeat-x;
}

p
{
    font-size:12px;
    color:#999999;
    line-height:160%;
}

#container
{
    width:1050px;
    background:url(images/bg.JPG) no-repeat;

    margin-top:0px;
    margin-left: auto;
    margin-right: auto;
    padding-left:150px;
    padding-top:220px;

}

回答by Laszlo the Wiz

There's something wrong with the jpg files. IE8 is not able to render them. Maybe you are using a JPEG2000 format?

jpg 文件有问题。IE8 无法呈现它们。也许您使用的是 JPEG2000 格式?

If you try to load "http://www.applezone.com.hk/newrx/images/bg.JPG" in IE8 you will get a broken picture icon only. I downloaded the file and opened it from the hard drive too, got the same result.

如果您尝试在 IE8 中加载“http://www.applezone.com.hk/newrx/images/bg.JPG”,您只会得到一个破碎的图片图标。我也下载了文件并从硬盘驱动器打开它,得到了相同的结果。

Try loading the pictures in an editor, like GIMP or PhotoFiltre and re-saving them (using save as)

尝试在编辑器中加载图片,如 GIMP 或 PhotoFiltre 并重新保存它们(使用另存为)

I tried in PhotoFiltre and re-saved it using a 90% quality setting. The size went down dramatically (to about 8% of the original without visible loss of quality) and IE8 is able to open it now!

我在 PhotoFiltre 中尝试并使用 90% 质量设置重新保存它。大小急剧下降(大约是原来的 8%,没有明显的质量损失),现在 IE8 可以打开它了!

You should try to make image files as small as possible on the site because that largely affects the visitors experience.

您应该尝试使网站上的图像文件尽可能小,因为这会极大地影响访问者的体验。

回答by Anson

It'd be help to know what version of IE you're using. Your code works fine for me in IE7. Anyway...

了解您使用的 IE 版本会有所帮助。你的代码在 IE7 中对我来说很好。反正...

background:url(images/bg_line.JPG);

Try this instead:

试试这个:

background-image:url('images/bg_line.JPG');

You're using the backgroundshorthand which is valid according to the standard, but it's possible whatever version of IE you're using doesn't support the way you're using it. IE may also expect the filename to be quoted, as I did for you.

您正在使用background根据标准有效的速记,但是您使用的任何版本的 IE 都可能不支持您使用它的方式。IE 也可能希望引用文件名,就像我为您所做的那样。