tags:

views:

165

answers:

6

Is there a way to completely ignore a CSS file from a header that is imported into your html file?

I want one page to have its own independent CSS not inheriting from any other CSS sources.

A: 

You could use JavaScript to remove the linked CSS file but then you would need to only add that JavaScript on that page.

Alternatively you could put an ID in the body tag and target a completely different set of CSS rules for that page:

Standard pages:

<body id="standard">

#standard h1 {
   color:blue;
}

The other page:

<body id="different">

#different h1 {
   color:red;
}

A bit of planning beforehand is well worth the effort

Matthew James Taylor
A: 

not really. there are ways to remove the css (like this: http://www.javascriptkit.com/javatutors/loadjavascriptcss2.shtml ) but it doesn't work in IE

Under what circumstances do you want to do this? Do you have no control over the page?

Luke Schafer
I can't remove the header file that adds all sorts of CSS information.
Daniel
+1  A: 

Isn't the obvious solution not to include that CSS file in this page?

cletus
I would but there is a header file that is included in every page of the project.
Daniel
+2  A: 

You could use !important declarations in your local stylesheet to override the standard inheritance.

http://www.w3.org/TR/CSS2/cascade.html#important-rules

cdonner
A: 

Put the content you don't want styled in an iframe, then the header will still appear on the page but the styles won't be inherited.

SpliFF
comment when you downvote damn it! was this downvoted because you think it doesn't work or because someone told you "frames are evil" and you apply that blindly to all contexts?
SpliFF
Upvoted to remove anonymous -and unhelpful- downvote.
David Thomas
+2  A: 

If you apply a unique id to the <body> of your custom page, you can easily make declarations specific to that page in your global css. There's no sense in serving a different css file really, as your global/site css will be cached on the client anyway.

Personally I think this is a good practice generally for managing page specific styles. In php you can achieve this dynamically in your view with

<body id="<?= basename($_SERVER['PHP_SELF'], ".php")?>">

in ASP.Net you can set an id using:

System.IO.Path.GetFileNameWithoutExtension(HttpContext.Current.Request.Url.AbsolutePath).ToLower
Bayard Randel