图片的CSS相对网址 [英] CSS relative url to images
问题描述
我正在本地主机上进行开发- http://localhost/mysite ,其中具有以下目录结构:
I am developing on my localhost - http://localhost/mysite, and within that I have the following directory structure:
-assets
--css
---styles.css
--images
---background.png
在styles.css文件中,我将得到以下内容,在localhost上可以正常使用
Within the styles.css file, I would have something the following, which works fine on localhost
background-image: url(../images/background.png);
但是,实时服务器在一个子域上运行- http://test.liveserver.com .这意味着css规则必须进行如下更改:
However, the live server works off a subdomain - http://test.liveserver.com. This means that the css rule has to change as follows:
background-image: url(/assets/images/loginlogo.png);
不确定要解决此问题的最佳方法吗?
Not sure on the best way to get around this?
推荐答案
通过提供的目录树,您不必更改路径.
With the directory tree you are providing you don't have to change your path.
..
表示CSS文件的父目录,因此暗指assets/
目录.
..
means the parent directory of the CSS file so the assets/
directory is implied.
这篇关于图片的CSS相对网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!