CSS child selector (>) doesn't work with IE

2020-02-26 11:43发布

The following CSS works well under firefox but doesn't work under IE browser, Why?
Also, how can I make only the elements, directly under the parent element, be affected by CSS?

CSS:

.box{font:24px;}
.box>div{font:18px}
.box>div>div{font:12px;}

HTML:

<div class="box">
   level1
   <div>
      level2
      <div> level3</div>
      <div> level3</div>
   </div>
   <div>
      level2
      <div> level3</div>
      <div> level3</div>
   </div>
</div>

3条回答
啃猪蹄的小仙女
2楼-- · 2020-02-26 12:22

I may be wrong about what you are looking for but this is how I would tackle your problem:

.box {font:24px;}
.box div {font:18px}
.box div div {font:12px;}

This will work fine for you example, however be aware that if you have another .box with div's in it they will be affected as well.

查看更多
疯言疯语
3楼-- · 2020-02-26 12:31

The child selector is not supported at all by IE6 and only partly by IE7.

Quirksmode.org: Child selector

CSS Compatibility tables

there is, sadly, no way to do this except to "un-declate" the definitions for all grandchildren.

查看更多
家丑人穷心不美
4楼-- · 2020-02-26 12:37

Internet Explorer supports the child selector (>) since version 7, but only in Standards mode. Make sure you are using a Doctype that triggers standards mode.

If you are targeting IE6 then you are out of luck. You need to either depend on JS or use descendant selectors.

a>b { foo }

becomes

a b { foo }
a * b { reverse-of-foo }
查看更多
登录 后发表回答