One way you could do this (if you're using Java) is to use jsp or a servlet to generate your css. If going the jsp route and you're using Spring tags, you could use the <spring:url>
tag to generate context-relative URLs.
I'm sure you could do it using PHP / ruby / whatever Microsoft technology in a similar manner.
See here for how to do this in Java.
What you'd basically have is this:
in web.xml:
<servlet-mapping>
<servlet-name>jsp</servlet-name>
<url-pattern>*.css</url-pattern>
</servlet-mapping>
in your .css file:
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring" %>
<spring:url var="myImage" value="/images/image.png" />
...
.myclass {
background: url(${myImage});
}
When this gets rendered, it becomes:
.myclass {
background: url(/context/images/image.png);
}
if your webapp is running in the /context
context.