Hello all, Can someone please help with this problem? How can I make one CSS dominant over the other? This is the CSS code. #content .highlight{ background: #F7FE2E; } #content .unhighlight{ background: #fff !important; } Code (markup): This is the issue. <span class="unhighlight"> text text text <span class="highlight">text text</span> text text text </span> Code (markup): The highlight is dominant because it is inside. I added "!important" (as you can see in my css code) but it doesn't fix the problem. How can I make unhighlight dominant? Is there another element I can use instead of span? div didn't work.
Sorry, I just edited my post. I did have it originally as "class". It was a typo :\ The problem is still there.
It may be easier I think if... the 'free' unwrapped text phrases could be made as child elements, as follows: <html> <head> <style type="text/css"> #content .highlight{ background: #F7FE2E; } [B] #content .unhighlight *{ background: #fff; }[/B] </style> </head> <body> <div id="content"> <span class="unhighlight"> [B]<span>text text text</span>[/B] <span class="highlight">text text</span> [B]<span>text text text</span>[/B] </span> </div> </body> </html> Code (markup):
This might sound like a stupid question, but wouldn't 'unhighlight' be the default state, and as such not NEED any stupid span with a class around it?!? Just saying, apply it 'unhighlight' to content, then use #content .highlight... Unless you have three states there, looks like a waste of code to me. Only wrap presentational markers around content that's DIFFERENT. Also, highlight is presentation, I'd be asking WHY is it highlighted. Is it receiving emphasis? What's making it different? Remember, HTML is for saying what things ARE, not what they look like -- a philosophy that should also be extended to your classes. A class like "Highlight" is just as bad as classes like "red" or "left" -- you might as well go back to using HTML 3.2 without CSS at that point. -- edit -- you could also try losing the ID selector and the !important -- that way they're equal level so the child should override the parent. Having the direct child selection changes the inheritance order.
I'm not sure if I'm reading this correctly but this has nothing to do with CSS it's HTML hierarchy...