Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apply CSS to Content Page in Asp.NET

Tags:

css

asp.net

Normally when we are using Master/Content style pages, we apply the css to Master page so every page child of the master page can use the style but I don't want this,I want I wanna apply css to content page directly instead of master page. Where should I put

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

that reference code ?

Thanks in advance by the way.

like image 892
Tarik Avatar asked Jul 12 '09 23:07

Tarik


People also ask

How to add CSS in ASP net content page?

Put a content placeholder in the head portion of your master page. Not all content pages will need to place anything in it but this particular content page can place the CSS file you want to link. Show activity on this post. You can't apply a style sheet to a content page only, it applies to the whole web page.

Can we use CSS in asp net?

ASP.NET Web pages function as HTML pages at run time. You can therefore use cascading style sheets (CSS) to set the appearance of any elements on the page other than Web server controls.


2 Answers

Normally I put a content placeholder in the head section of the master page. That way any content page can add extra css/js/etc references to the head of the page.

In your master page put the following

<head>
  ... title, meta tags, js and css links ...
  <asp:contentPlaceholder id="head" runat="server" />
</head>

Then in your pages you can include extra elements in the head using this

<asp:content contentplaceholderid="head" runat="server">
 <link rel="stylesheet" href="css/lightbox.css" type="text/css" media="screen" />
</asp:content>
like image 171
Steve Temple Avatar answered Sep 19 '22 09:09

Steve Temple


Put a content placeholder in the head portion of your master page. Not all content pages will need to place anything in it but this particular content page can place the CSS file you want to link.

like image 24
Spencer Ruport Avatar answered Sep 21 '22 09:09

Spencer Ruport