Master Pages and CSS

  • Thread starter =?ISO-8859-1?Q?Mika=EBl_PLOUHINEC?=
  • Start date
?

=?ISO-8859-1?Q?Mika=EBl_PLOUHINEC?=

Hello,

I have created a master page with a css.

How can I use css in the children pages? The css must be declared in the
<head> </head> section. Does I have to import all my css in my master?
Is there a way to import only one css for one children page?

Thanks a lot.

Mike.
 
J

John Timney \(MVP\)

Your content placeholders at delivery become part of the page delivered,
which includes your CSS. AS long as you reference the CSS class ID's in
your controls and output the css should be picked up.

If you wish to change the CSS entirely based on which contentplaceholder is
loaded then you can do that in the page load event of the placeholder.

<head>
<link id="cssStyleSheet" rel="stylesheet" type="text/css" runat="server" />
</head>

Sub Page_Load(Sender As Object, E As EventArgs)
If Not (IsPostBack)
cssStyleSheet.Attributes.Add("href","Stylesheet1.css")
End If
End Sub

--
Regards

John Timney (MVP)
VISIT MY WEBSITE:
http://www.johntimney.com
http://www.johntimney.com/blog
 
?

=?ISO-8859-1?Q?Mika=EBl_PLOUHINEC?=

I'm sorry but I'm not sure I understand what you tell me.

Your
<head>
<link id="cssStyleSheet" rel="stylesheet" type="text/css" runat="server" />
</head>

is in the master page isn't it?

So you tell me that I have to add my css with
cssStyleSheet.Attributes.Add("href","Stylesheet1.css")
in the page_load of my children page, no?

Maybe I don't think correctly about my problem.

I have several web pages which the header and the left menu are
identical. So I would like to use master page (I think it is a good way
to do that). I have created a master page and a css (only for the master
page elements).
Moreover, the content placeholders of my childrens pages have to be
constructed with a different css for all my childrens pages (on page =
one css).

Does your method answer to my question?

Thanks a lot for your help.

Mike.



John Timney (MVP) a écrit :
 
J

John Timney \(MVP\)

I'm sorry but I'm not sure I understand what you tell me.
Your
<head>
<link id="cssStyleSheet" rel="stylesheet" type="text/css" runat="server"
/>
</head>

is in the master page isn't it?

Yes, but you could also have a common stylesheet link to a top level
stylesheet along with this containing your master page CSS code only
So you tell me that I have to add my css with
cssStyleSheet.Attributes.Add("href","Stylesheet1.css")
in the page_load of my children page, no?

yes, if you want to seperate and only load your child CSS in the placeholder
load event.
Maybe I don't think correctly about my problem.

I have several web pages which the header and the left menu are identical.
So I would like to use master page (I think it is a good way to do that).
I have created a master page and a css (only for the master page
elements).

You should add all CSS elements to your master where possible
Moreover, the content placeholders of my childrens pages have to be
constructed with a different css for all my childrens pages (on page = one
css).

.........thats what the code I sent allows you to do....load the css file
only at child load

--
Regards

John Timney (MVP)
VISIT MY WEBSITE:
http://www.johntimney.com
http://www.johntimney.com/blog
 
?

=?ISO-8859-1?Q?Mika=EBl_PLOUHINEC?=

Ok.

Thanks a lot for your answers.

Mike


John Timney (MVP) a écrit :
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top