不幸的是,Firefox在这里有一个愚蠢的错误,路径是相对于页面的路径,而不是相对于CSS文件的位置。这意味着如果您在树中具有不同位置的页面(如在根目录中具有Default.aspx,并且在View文件夹中具有Information.aspx),则无法使用工作相对路径。 (IE将正确地解决相对于CSS文件位置的路径。)
re: Making sense of ASP.Net Paths by
Russ Brooks February 25, 2006 @ 8:43
am
No one fully answered Brant’s question
about the image paths inside the CSS
file itself. I’ve got the answer. The
question was, “How do we use
application-relative image paths
INSIDE the CSS file?” I have long been
frustrated by this very problem too,
so I just spent the last 3 hours
working out a solution.
The solution is to run your CSS files
through the ASPX page handler, then
use a small bit of server-side code in
each of the paths to output the root
application path. Ready?
Add to web.config:
Inside your CSS, use the Request.ApplicationPath property
wherever a path exists, like this:
#content {
background: url(
%>/images/bg_content.gif) repeat-y;
}
.NET serves up ASPX pages with a MIME type of “text/html” by default,
consequently, your new server-side CSS
pages are served up with this MIME
type which causes non-IE browsers to
not read the CSS file correctly. We
need to override this to be
“text/css”. Simply add this line as
the first line of your CSS file:
06001