Magiranu Magiranu - 6 months ago 50
CSS Question

CSS ID-Selector in combination with Class-Selector not working

I'm not able to use an ID-selctor in combination with a class-selector. It baffles me as I also used a CSS Validator to check for erors. So, why is only the latter working in my code?

This is my Code:

#result .red1 {
color: #FF0000;

.red2 {
color: #FF0000;

<span id="result" class="red1">Test of Color</span>
<span id="result" class="red2">Test of Color</span>

Answer Source

Remove the space between the ID and the class selector

#result.red1 {
  color: #FF0000;

"#result .red1" means find the class red1 INSIDE the result element. It is better not to use ID as CSS selectors though.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download