Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Url.Content() in Style Sheet?

I have a CSS class that references a background image :

#content-wrapper
{
    background: #f7f7f7 url('/Images/bg04.png');
    border-top: solid 1px #fff;
    padding: 45px 0 45px 0;
}

I've been using MVC4 with Razor for a little while now, and I've gotten used to using @Url.Content() to link to images, other pages, and also documents available on the site.

However, it doesn't look like this particular helper (or any really) is available outside of .cshtml pages.

My Question :

Is there any way to "enable" the use of @Url.Content() on a style sheet?

like image 452
X3074861X Avatar asked Mar 22 '23 16:03

X3074861X


1 Answers

Not easily, and I haven't run into a situation yet where it is needed since the paths are relative to the stylesheet (not the page, which may change). Although, instead of using an absolute path like url('/Images/bg04.png') you should use a relative url, like url('../Images/bg04.png')

So if you store your CSS in ~/content and your images are in ~/images, then all the paths in your stylesheet should begin with ../images/

like image 146
Robert McKee Avatar answered Mar 31 '23 13:03

Robert McKee