Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Visual Studio not resolve my CSS class names?

Whenever I am working in Visual Studio I always found that it will not resolve the css class names in my html. The CSS Class names will appear with the green squiggly line in Visual Studio but then the page will render fine when viewing it in the browser. So I know the css file is referenced correctly in my master page but Visual Studio is just failing to resolve it. Also the Design View will not show any of the css styles either.

like image 321
Jeff Widmer Avatar asked Jun 07 '09 10:06

Jeff Widmer


People also ask

Why my CSS file is not working in VS code?

The problem may be that your browser is caching the CSS file. If you're debugging with Edge, you can open the F12 tools and click on the Network tab. At the top, you'll find a button to "always refresh from server." Turn this on, and files won't be cached.

Where is the CSS class code in Visual Studio?

Normally, you can right-click on a method and select "Go To Definition" (F12) or "Find All References" (SHIFT+F12). You can even go to the definition of a css class from your aspx page by pressing F12 (if your cursor is over the CssClass name).

Does class name matter CSS?

No, it does not.


1 Answers

See this post by Jeff King about getting Visual Studio to be able to find the javascript file with the intellisense: JScript IntelliSense FAQ.

In particular read point #4, third bullet:

Site-Relative Paths - These are paths of the form "/folder/file", and is calculated from the base of your site (http://site/application/folder/file). This approach is supported by ASP.NET Web Forms and ASP.NET MVC. However, it is not supported by Visual Studio. The reason is because Visual Studio does not always know the final deployed location of your site and thus the path resolution cannot be guaranteed. Given that quite we've seen few folks are using site-relative paths, we could consider making an assumption just resolving this type of path to the root of the project. Given the risk that you may think your site is working when it's really not, I wanted to see how many people were supportive of this.

Notice the “[Site-Relative Paths are] NOT supported by Visual Studio”. I always use site relative paths for my javascript and css files so the solution to get Visual Studio to find your javascript files is the same solution to get Visual Studio to find your css files:

<link href="/content/default.css" rel="stylesheet" type="text/css" />
<% if (false) {%>
    <link href="../../content/default.css" rel="stylesheet" type="text/css" />
<% } %>

And now Visual Studio can find the CSS file and validate my CSS Class names exist (and Design View looks so much better too).

Posted on my blog here: Why does Visual Studio not resolve my CSS class names?

-Jeff

like image 99
Jeff Widmer Avatar answered Sep 19 '22 23:09

Jeff Widmer