CSS2 selectors and style overrides
This is HTML:
<div id="testBlue"> <span>hello</span> <span id="testGreen" class="testGreen">hello2</span> </div> If I installed in CSS:
#testBlue span { color:Blue; } .testGreen, #testGreen { color:Green; } How can I override the general style in the second SPAN?
I have tried both id ids and class selectors, but it does not override it.
In CSS, selectors with higher selectivity override specificity, which are more general.
In your example, you defined a style for span inside a div with id = "testBlue" . This selector is more specific than a simple selector for the class or id testGreen , so it wins. You just need a selector more specific than the #testBlue span , which is easy to find:
#testBlue span.testGreen { color: green; } Do not use important, give it more weight, like this
#testBlue span { color:Blue; } #testblue #testgreen{color:Red} Edit
I was taught to use! Bad practice is important.
Some objects in css have different weight in the decision to apply the rule
See http://htmldog.com/guides/cssadvanced/specificity/
I believe that it is not wrong to use important, but best practice, to use weighting to clarify