Why doesn't Visual Studio resolve CSS class names?

Whenever I work in Visual Studio, I always find that it will not resolve CSS class names in my html. CSS class names will display with a green bar in Visual Studio, but then the page will display fine when viewed in a browser. Therefore, I know that the css file correctly links to my main page, but Visual Studio just does not allow it. In addition, none of the CSS styles will be displayed in the Design View.

+7
css visual-studio
source share
3 answers

See this post by Jeff King about how Visual Studio can find a javascript file using the intellisense: JScript IntelliSense FAQ .

In particular, reading point No. 4, third line:

Site-relative paths are paths of the form "/ folder / file" and are 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 that Visual Studio does not always know the final deployed location of your site and therefore path resolution cannot be guaranteed. Given that we have quite a few people using the site-relative paths, we might consider creating an assumption that simply allows this type of path to the root of the project. Given the risk that your site works when itโ€™s really not, I wanted to see how many people were supporting it.

Please note that "[Regarding Sites] is not supported by Visual Studio." I always use relative site paths for my javascript and css files, so the decision to get Visual Studio to find your javascript files is the same solution so that Visual Studio can 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 check my CSS class names (and the Design View looks much better).

Wrote my blog here: Why doesn't Visual Studio resolve CSS class names?

-Jeff

+8
source share

I just saw the answer to this question, so I thought that I would share it. You can make VS2008 recognize your CSS file by going to the View / Manage Styles toolbar and thereby adding a CSS file. When I did this, I saw my CSS file in the Manage Styles list, but it had a warning icon because VS for some reason did not see it. I deleted and re-added it, and now VS find my styles (no green error) and Intellisense works. Very lightly!

+2
source share

Tried to just close the project and open it again? Perhaps this is a bit slower, or you are using some kind of style sheet path (generated from other data or something else) that cannot be read directly by VS.

It has never been the same (VS08).

0
source share

All Articles