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?
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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With