JavaScript / CSS /图片参考路径 [英] JavaScript/ CSS/ Image reference paths
问题描述
我想知道是否有人喜欢在其网站中引用图片/ css或javascript文件?
I was wondering if anyone has any preference for referencing images/ css or javascript files in their sites?
我问的原因是,如果客户想要托管网站,我们写在一个虚拟目录下,网站通常必须有它的文件引用更改 - 甚至下来到CSS文件中的url(...图像路径),因为我们通常开发的网站,如果它是一个根应用程序 - 有时客户端不知道他们将要寄存它,直到下降日期前一天!
The reason I ask is if a client wants to host the site we've writen under a virtual directory, the site usually has to have it's file references changed - even down to url (...image path) in CSS files because we usually develop the site as if it's a root application - sometimes the client doesn't know where they're going to host it until the day before drop-date!
使用ASP.NET我们可以解决表单中的问题在使用ASP.NET MVC时,使用runat服务器组件或Url.Content方法引用使用'〜'的项目
Using ASP.NET we can get around the problem in the forms by referencing items using the '~' when using runat server components or the Url.Content method when using ASP.NET MVC...
因此,有没有什么好的解决方案
So, are there any good solutions for keeping the file references generic or are we faced with having to change the file references everytime?
推荐答案
图片
示例:
/img/a.gif
/css/c.css
要引用css文件中的 a.gif
,必须始终引用它,如 ../ img / a.gif
,与网页所在位置或如何重写无关。
To reference a.gif
from the css file, you must always reference it like such ../img/a.gif
, irrelevant to where a page is located or how it is rewritten
这篇关于JavaScript / CSS /图片参考路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!