简体   繁体   English

CSS子选择器(>)不适用于IE

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

The following CSS works well under firefox but doesn't work under IE browser, Why? 以下CSS在Firefox下运行良好,但在IE浏览器下无效,为什么?
Also, how can I make only the elements, directly under the parent element, be affected by CSS? 另外,我如何只使用直接在父元素下的元素受CSS影响?

CSS: CSS:

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

HTML: HTML:

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

Internet Explorer supports the child selector ( > ) since version 7, but only in Standards mode. Internet Explorer从版本7开始支持子选择器( > ),但仅在标准模式下支持。 Make sure you are using a Doctype that triggers standards mode . 确保您使用的是触发标准模式的Doctype

If you are targeting IE6 then you are out of luck. 如果你的目标是IE6,那么你就不走运了。 You need to either depend on JS or use descendant selectors. 您需要依赖JS或使用后代选择器。

a>b { foo }

becomes

a b { foo }
a * b { reverse-of-foo }

The child selector is not supported at all by IE6 and only partly by IE7. IE6完全不支持子选择器,IE7只支持部分选择器。

Quirksmode.org: Child selector Quirksmode.org:子选择器

CSS Compatibility tables CSS兼容性表

there is, sadly, no way to do this except to "un-declate" the definitions for all grandchildren. 遗憾的是,除了“解除”所有孙子孙女的定义之外,没有办法做到这一点。

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. 这对你来说很好,但要注意,如果你有另一个带有div的.box,它们也会受到影响。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM