How do I prevent CSS inheritance?
You either use the child selector
So using
#parent > child
Will make only the first level children to have the styles applied. Unfortunately IE6 doesn't support the child selector.
Otherwise you can use
#parent child child
To set another specific styles to children that are more than one level below.
There is a property called all
in the CSS3 inheritance module. It works like this:
#sidebar ul li {
all: initial;
}
As of 2016-12, all browsers but IE/Edge and Opera Mini support this property.
As of yet there are no parent selectors (or as Shaun Inman calls them, qualified selectors), so you will have to apply styles to the child list items to override the styles on the parent list items.
Cascading is sort of the whole point of Cascading Style Sheets, hence the name.
You can use the * selector to change the child styles back to the default
example
#parent {
white-space: pre-wrap;
}
#parent * {
white-space: initial;
}