CSS background-image属性不加载 [英] CSS background-image property not loading

查看:724
本文介绍了CSS background-image属性不加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在网站上工作,目前在首页上。我有一个以前写的CSS头,并想要替换图像的头文件< div> 的背景,而不是一个纯色,如在以前的设计。我有一个头图像,在 img / header.jpg 目录。我使用 background-image 属性加载背景图片,如下所示:

I am working on a website, and am currently on the homepage. I had a previously-written CSS header, and wanted to substitute an image for the background of the header <div> instead of a solid color, as in the previous design. I have a header image, in the img/header.jpg directory. I am loading the background image using the background-image property like so:

background-image: url(img/header.jpg)

问题是,加载图像,背景是银色(这是< body> 的背景设置为)。

任何人都可以告诉我我在这里做错了什么? (我测试它的浏览器是IE8,如果这可能与它有关):

The problem is, it does not load the image, the background is just silver (which is what the background of the <body> is set to).
Can anybody tell me what I am doing wrong here? (the browser I am testing it in is IE8, if that might have anything to do with it :)

推荐答案

在一个单独的CSS文件注意urls应该是相对于这个CSS文件的位置。例如,如果您的CSS文件位于〜/ styles / main.css 中,则规则应为:

If this is in a separate CSS file note that urls should be relative to the location of this CSS file. So for example if your CSS file is located in ~/styles/main.css the rule should be:

background-image: url('../img/header.jpg')

假设图片位于〜/ img / header.jpg

这篇关于CSS background-image属性不加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆