Visual Studio 2008 not applying my stylesheet

  • Thread starter Thread starter Nathan Sokalski
  • Start date Start date
N

Nathan Sokalski

I have a stylesheet in the <head> section of my Master Page which is
declared as follows:

<link href="/nathansokalski_com.css" rel="stylesheet" type="text/css"/>

Very simple link tag using a file in the root for the href. Visual Studio is
not telling me it is incorrect or the file doesn't exist or complaining in
any other way about this tag. However, it is telling me that the values from
this *.css file for all of my class and CssClass attributes are not defined.
However, if I change the link tag to the following:

<link href="nathansokalski_com.css" rel="stylesheet" type="text/css"/>

and remove the / from the href value, Visual Studio is able to find all my
style rules in the file. I realize that either one of these will work
correctly, since ASP.NET automatically modifies the href as necessary, but I
want to use the / for the following reasons:

1. I want to be able to copy and paste this code to any Page or Master Page
in any directory without modifying it
2. I should be allowed to use any valid XHTML without recieving errors
3. It usually means a smaller download for the user (maybe only by two
characters, but every bit counts)

Why is Visual Studio 2008 not letting me use a root-relative path for my
link tag's href attribute? Any help would be appreciated. Thanks.
 
Nathan Sokalski said:
I have a stylesheet in the <head> section of my Master Page which is
declared as follows:

<link href="/nathansokalski_com.css" rel="stylesheet" type="text/css"/>

Very simple link tag using a file in the root for the href. Visual Studio
is not telling me it is incorrect or the file doesn't exist or complaining
in any other way about this tag. However, it is telling me that the values
from this *.css file for all of my class and CssClass attributes are not
defined. However, if I change the link tag to the following:

<link href="nathansokalski_com.css" rel="stylesheet" type="text/css"/>

and remove the / from the href value, Visual Studio is able to find all my
style rules in the file. I realize that either one of these will work
correctly, since ASP.NET automatically modifies the href as necessary, but
I want to use the / for the following reasons:

1. I want to be able to copy and paste this code to any Page or Master
Page in any directory without modifying it
2. I should be allowed to use any valid XHTML without recieving errors
3. It usually means a smaller download for the user (maybe only by two
characters, but every bit counts)

Why is Visual Studio 2008 not letting me use a root-relative path for my
link tag's href attribute? Any help would be appreciated. Thanks.


Try:-

<link href="~/nathansokalski_com.css" rel="stylesheet" type="text/css"/>

and make sure your head element has the runat="server" attribute.
 
I thought about doing that as well, but once again that is not valid XHTML
and it will be modified just like using href="nathansokalski_com.css" would
be. But more importantly, Visual Studio 2008 still gives me the error "The
class or CssClass value is not defined." when I use your suggestion. Any
other ideas?
 
The problem is that first '/' indicates Root of the website and in Visual
Studio root is /projectname.
So if you change /nathansokalski_com.css to
/projectname/nathansokalski_com.css then it will work in Visual Studio.

But then break your production if you move to the root of the server and
there will be no /projectname there.
So the solution to just ignore it.

Go to menu Tools/Options check "Show all settings" on the bottom then
TextEditors/CSS/CSS SPecific and uncheck detect errors.

George.
 
I have been struggling with the exact same problem. I realize I can ignore
these errors, as George suggests, however, I feel that there should be some
way to define css include files so that they both work in production and are
used by the designer. It's hard to use the designer properly, if the styles
are wrong.
 
Back
Top