从我的CSS文件找不到背景图片 [英] Background image not found from my css file

查看:35
本文介绍了从我的CSS文件找不到背景图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的CSS文件位置htdoc/anyFolder/css/style.css和图像文件夹文件位置htdoc/anyFolder/image/search.png.我在css文件中使用了背景图片规则,例如 background-image:url("/image/search.png"); 但我找不到图像.浏览器查找 http://localhost/image/search.png ,而浏览器应查找 http://localhost/anyFolder/image/search.png .问题出在哪儿.我尝试过

My css file location htdoc/anyFolder/css/style.css and image folder file location htdoc/anyFolder/image/search.png. I used background-image rule in css file like background-image: url("/image/search.png"); but i does not find the image. Browser look for http://localhost/image/search.png while it should look for http://localhost/anyFolder/image/search.png. Where is the problem. I tried

background-image: url("../image/search.png");

background-image: url("/../image/search.png");

background-image: url("./../image/search.png");

没有一项工作.找不到问题所在.是否取决于css文件所在的位置.

none of this work. Cannot find where is the problem. Does it depends on where the css file is included.

推荐答案

如果您的路径是 htdoc/anyFolder/css/style.css htdoc/anyFolder/image/search.png

这应该有效:

background-image: url("../image/search.png");

这也应该起作用:

background-image: url("/anyFolder/image/search.png");

但是您说他们没有.您应该检查文件和文件夹的名称是否正确,以及HTML上是否具有 base 元素,因为它可能会更改浏览器查找文件的路径.

But you say they didn't. You should check if the names of files and folders are correct and also if you have the base element on HTML, because it could change the path where the browser looks for files.

这篇关于从我的CSS文件找不到背景图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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