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.
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.
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
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?
Isn't the obvious solution not to include that CSS file in this page?
You could use !important declarations in your local stylesheet to override the standard inheritance.
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.
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