Hi! I read that IE 8 accepts child selectors. But it does not seem to work for my IE8 (Spanish version if this even matters).

#div > p{background-color: blue;}
========================
<div id="div">
<p>Shoud work here!</p>
        <div>
                <p>and not here</p>
        </div>
</div>

It works for firefox and not for internet explorer. What could be happening?

Dani AI

Generated

IE8 does implement the child combinator when it is actually running in a standards-capable mode. If the selector in 's example works in Firefox but not in IE8, the page is most likely being rendered in Quirks or an IE7-compatibility mode (this disables some CSS selectors). See MDN on the child combinator for the supported behavior: Child combinator (>) on MDN.

Common causes and quick checks:

  • Confirm the document is in Standards mode (missing or legacy DOCTYPE will trigger Quirks). A minimal modern DOCTYPE is:
    <!DOCTYPE html>
  • IE8 can be forced into compatibility/IE7 mode by intranet settings or the X-UA-Compatible header. The F12 Developer Tools report the current Document Mode and Browser Mode; use that to verify the rendering engine. MDN explains quirks vs standards mode: Quirks Mode and Standards Mode.

Other things to verify:

  • Malformed HTML (unclosed tags) can change DOM structure and break selector matches. Run the page through the W3C validator to catch markup problems: W3C Markup Validation Service.
  • As noted, avoid using tag names as id/class identifiers (for example an id literally named "div"); renaming to a semantic id reduces risk of parser quirks or developer confusion.

About the suggested workaround: ’s approach—apply a broad rule, then neutralize it for deeper descendants—works because CSS specificity and source order determine which rules win. It’s a valid fallback, but fixing the document mode/markup is the more robust solution so the standard child selector behaves as expected.

Recommended Answers

All 2 Replies

Hi! I read that IE 8 accepts child selectors. But it does not seem to work for my IE8 (Spanish version if this even matters).

#div > p{background-color: blue;}
========================
<div id="div">
<p>Shoud work here!</p>
        <div>
                <p>and not here</p>
        </div>
</div>

It works for firefox and not for internet explorer. What could be happening?

What DTD are you using? Might require STRICT mode.
But if you are working in a strict document than it will mean it doesn't support direct child selector syntax.

But this is a highly effective workaround - try this.

<style type="text/css">
            #div p{background-color: blue;}
            #div div p{background-color: transparent;}
	</style>

IE sometimes gets confused when you name a class or an id using a tag name.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.