0

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.

6 Answers 6

3

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

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

Sign up to request clarification or add additional context in comments.

Comments

3

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

Comments

1

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

1 Comment

I would but there is a header file that is included in every page of the project.
0

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

Comments

0

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?

1 Comment

I can't remove the header file that adds all sorts of CSS information.
0

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.

1 Comment

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?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.