简体   繁体   English

IE8及更低版本中未显示CSS“背景图片”

[英]CSS “background-image” not showing in IE8 and below

No matter what I do I cannot get the background-image property to work correctly in IE8. 无论我做什么,我都无法使background-image属性在IE8中正常工作。
I've even stripped everything down to the bare minimum and just have a functioning HTML page: 我什至将所有内容都减少到最低限度,并且只有一个正常运行的HTML页面:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Welcome to Fritz PT!</title>
    <link rel="stylesheet" href="css/style.css">
</head>
<body>
    <div class="myClass">

    </div>      
</body>
</html>

with the CSS for the class as follows: 该类的CSS如下:

.myClass {
    background-image: url(/images/header_image_fallback.gif);
    height: 300px;
    width: 300px;
}

but still nothing is showing up in IE8 and lower. 但在IE8及更低版本中仍然没有任何显示。

I have tried multiple image formats (.gif, .jpg, .png), putting quotes around the folder path ('/images/header_image_fallback.gif') and then HTML. 我尝试了多种图像格式(.gif,.jpg,.png),在文件夹路径('/images/header_image_fallback.gif')和HTML前后加引号。 Does IE8 not support the background-image property? IE8不支持background-image属性吗? If it makes a difference I'm currently testing this out in VirtualBox. 如果有所作为,我目前正在VirtualBox中进行测试。

Okay, if anyone else is having the same problem as me I found the issue. 好吧,如果其他人遇到与我相同的问题,我就发现了问题。 Apparently, even though the syntax works in all modern browsers, you need to make sure you have the ../ for the folder path for IE. 显然,即使该语法在所有现代浏览器中均可用,您仍需要确保IE的文件夹路径具有../。 So in my original code (which works in modern browsers) I had the folder path as seen above /images/header_image_fallback.gif however, for IE I would need to do this ../images/header_image_fallback.gif. 因此,在我的原始代码(在现代浏览器中可用)中,我具有如上/images/header_image_fallback.gif所示的文件夹路径,但是对于IE,我需要这样做../images/header_image_fallback.gif。 My images folder is up a directory from my css file and I suppose that matters for IE as opposed to modern browsers 我的images文件夹位于css文件的目录中,我认为这对于IE来说很重要,而与现代浏览器不同

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

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