如何在css URL中使用相对/绝对路径? [英] How to use relative/absolute paths in css URLs?
问题描述
我有一个生产和开发服务器。
问题是目录结构。
I have a production and development server. The problem is the directory structure.
开发:
-
http://dev.com/subdir/images/image.jpg
-
http:// dev .com / subdir / resources / css / style.css
http://dev.com/subdir/images/image.jpg
http://dev.com/subdir/resources/css/style.css
生产:
-
http://live.com/images/image.jpg
-
http://live.com/resources/css/style.css
http://live.com/images/image.jpg
http://live.com/resources/css/style.css
如何在 css
文件夹中使用 style.css
background:url
属性?
How can I have a style.css
in css
folder that uses on both servers the same path for the background: url
property? Is there a trick I can use with relative paths?
推荐答案
这个url是相对于CSS文件的位置,所以这应该适合你:
The url is relative to the location of the CSS file, so this should work for you:
url('../../images/image.jpg')
相对URL将两个文件夹放回,然后到图像
文件夹
The relative url goes two folders back, and then to the images
folder - it should work for both cases, as long as the structure is the same.
从http://www.w3.org/TR/REC-CSS1/#url :
部分URL相对于样式表的来源而不是相对于文档进行解释
Partial URLs are interpreted relative to the source of the style sheet, not relative to the document
这篇关于如何在css URL中使用相对/绝对路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!