OrElse
OrElse

Reputation: 9959

Why is CSS applied only into my master page?

In the head portion of my Master page i have a link to an external CSS file

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

Although i am able to apply the style in child pages in design time...

<asp:Label ID="Label" runat="server" CssClass="BodyText" Text="This is a link"></asp:Label>

...in run time child pages have no style.

So, What am i missing here?

Upvotes: 0

Views: 1061

Answers (3)

Gabriel McAdams
Gabriel McAdams

Reputation: 58261

The path to the CSS file (and any other file - images, javascript, etc) is relative to the page (the page address in the browser). If the master page is in a different folder than the page, then the css file may not be found.

Try using either an absolute path, a path relative to the root, or a path to the CSS file like this:

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

Upvotes: 1

Daniel Vassallo
Daniel Vassallo

Reputation: 344311

Try using the root operator "~" for stylesheets in your master page:

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

ASP.NET resolves the ~ operator to the root of the current application. You can use the ~ operator in conjunction with folders to specify a path that is based on the current root.

Upvotes: 1

Jens Schauder
Jens Schauder

Reputation: 81907

If your child pages are in a subdirectory, they'll expect the style sheet in that directory as well. changing the reference to the style sheet to ../style.css or /style.css should help.

Upvotes: 2

Related Questions