CSS - Inherit nothing

Associate
Joined
6 Jan 2006
Posts
1,024
Location
Midlands
Hi,

I have a div and inside this div, i do not want to inherit any css!

Inside this div, i do not want any css.

Is this possible, instead of overriding every previous css?
 
AFAIK there is no way of stopping inheritance.

The easiest way would be to use class or id selectors on the parent elements, rather than just applying styles at the element level.
 
Use selectors to find the div and apply an alternative style, this means you won't need to apply a class to said div element.....

If the div in question is always the first div after the one with the class you would do it like so....

Code:
div.yourclass > div:first-child {color:#fff}
Of course the color was just an example as was the div class name....

Bear in mind if your div in question is sat inside another element you will need to include that in the selector, i can provide further examples if needed.

If you're ok with reading about how to use them you can find the info here..
http://www.w3.org/TR/CSS2/selector.html

As said, i don't mind providing examples...
 
Last edited:
Use selectors to find the div and apply an alternative style, this means you won't need to apply a class to said div element.....

If the div in question is always the first div after the one with the class you would do it like so....

Code:
div.yourclass > div:first-child {color:#fff}
Of course the color was just an example as was the div class name....

Bear in mind if your div in question is sat inside another element you will need to include that in the selector, i can provide further examples if needed.

If you're ok with reading about how to use them you can find the info here..
http://www.w3.org/TR/CSS2/selector.html

As said, i don't mind providing examples...

This won't workin IE6 though
 
Will it not?

Why not, due to the first-child selector?

If so, you can do it without that, you'll just need to make sure you use a specific selector that applies to the given area and doesn't effect others.

Or is it that selectors will not work fullstop in IE6?

When it comes to webpages, if the question is "can we make X do Y?", 9 times out of 10 the answer is yes depending on the language you are writing in which has it's own limitations of course. So the question remaining is simply, how?

If you the OP would post the code he/she is working with it would be a whole lot easier.
 
Back
Top Bottom