views:

55

answers:

5

In the root of my domain i have the CSS file style.css and the masterpage file site.master.

The link to the CSS file within the site.master is

<link href="style.css" rel="stylesheet" type="text/css" media="screen" />

The problem is that webpages contained within subdirectories do not inherit the CSS file.

What am i doing wrong here?

If i copy the style.css file to the subdirectories everything works like a charm...

UPDATE: If i change the path to /style.css or to ~/style.css the style is Not applied also to the webpages within the root folder.

+1  A: 

Well the obvious question is, does the other pages inherit the correct masterpage, namely the one with your css link?

ie.

<%@ Page Language="C#" MasterPageFile="~/MasterPage.master"...

also perhaps '/' before file name would help

Ehsan
Hello, could you please check the update i posted?
Chocol8
Try removing "media=screen" line and Did you check your spelling? Also try doing runat="server"...let's see what happens
Ehsan
Sorry... same results
Chocol8
Is the css <link....> in the <head> section of the MasterPage and does the head have its runat="server" attribute? And you've checked the other pages inherit the correct master page as I've explained above?
Ehsan
+1  A: 

You need to specify the path as /style.css.

Novikov
+1  A: 

MasterPages use the containing page for the path.

change your css tag to be a server control and use the "~" root symbol.

    <link id="lnkStyle" runat="server" href="~/style.css" 
                              rel="stylesheet" type="text/css" />
Bobby Borszich
A: 

If you're including that link tag in your master page, the HTML being output by the content pages in subdirectories contains a link to "style.css", which the browser looks for in that directory.

If you're developing in ASP.NET, you should be placing your CSS files in themes, which will take care of this problem. If you really don't want to do that for some reason, make the URL to the stylesheet an application-relative path ("~/style.css") and make the link tag executed on the server; I believe that that will resolve the application path and generate an absolute URL.

ngroot
A: 

Try this:

<link href="<%: Url.Content("~/style.css") %> rel="stylesheet" type="text/css" media="screen" />

It will make the path relative to your hostname, giving the correct path to your pages in the subdirectories. Right now, just linking style.css gives it the folder relative path, so its looking inside of the same folder your page is in, instead of where you intended. Hope that helps. You could also re-write your link with a preceding forward slash, like "/style.css" and that should also do the trick.

Gallen