What is the correct way to embed embedded server tags in a CSS section of a page?

I am trying to put some inline server tags on a page so that I can get the correct path for the image using Visual Studio 2012.

I do it like this:

<style type="text/css">
.someclass
{
    background-image: url(<%=Url.Content("~/Content/Images/messageIcon.gif")%>);
}
</style>

The problem is that once this is written, the entire style section loses color formatting using the VS2012 editor. Is there any other way to do this (or an option in VS2012) so that I don't lose color and padding?

+5
source share
2 answers

The reason why the visual studio is losing its education is because you mix css code and server code as shown below.

<style type="text/css"> 
.someclass  
{     
    background-image: url(<%=Url.Content("~/Content/Images/messageIcon.gif")%>);
}    
</style> 

You must separate your css from your code.

css, css, , , , Url.Content(~)

.someclass  
{     
     background-image: url(../Images/messageIcon.gif); 
}    
+3

Visual Studio Highlight CSS. URL- , .

CSS, style html-. :

<div class="beautiful-button" style="background-image: url('<%=Url.Content("~/Content/Images/messageIcon.gif")%>')">
...
</div>

, URL- (). , :

<asp:MyOwnControl runat="server" class="beautiful-button" URL="~/Content/Images/messageIcon.gif" />
+3

All Articles