CSS Conditional comments not working(Updated To: IE specific css?)

679 views Asked by At

I have been trying to get the CSS conditional comments working on MVC.(Conditional Comment below). I have been looking for the answer on google but they all seem to have the same code but working. But It doesn't seem to work for mine. Is there a problem in the code? It seems as thought it takes it as a comment. Does it not work for MVC Razor? Does it have anything to do with IE versions? If this question was already please feel free to link it for me! (Look at update)

<!--[if IE]>
<link rel="stylesheet" href="~/Content/BrowseStyle2.css" />
<![endif]-->

UPDATE

Conditional comments are not supported in IE 10. Is there another way to get IE specific Css files working or IE specific CSS classes?

2

There are 2 answers

1
Tom On

What's the "~" doing in the path to the CSS File?

0
Gene Parcellano On

It's the "~". I had the same issue. For some reason it's not being rendered on the server side, I guess since it's wrapped in IE conditional comments. You have two options:

  1. Use the full URL of the file
  2. Or do something like

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

I hope that helps.