Root root site in css

Is it possible to get a relative translation of the site root in the CSS file of an MVC3 application?

In .cshtml, I can use:

<link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" /> 

However, in CSS, I need to access the content, for example:

 background-image: url('/Content/images/banner.png'); 

I would like to be able to get root as I can with @ Url.Content, so I can do something like this (which obviously doesn't work):

 background-image: url(@Url.Content("~/Content/images/banner.png")); 
+4
source share
1 answer

URLs in css files relative to css file - is it impossible to specify a relative url?

If not, you will need to process the ASP.NET file. You can either add a mapping so that all css files are processed by the ASP.NET engine, or rename the css file to a file with an extension that is already processed by ASP.NET - for example, .aspx. You will probably also need a page directive to make it work ...

+3
source

Source: https://habr.com/ru/post/1343486/


All Articles