我对有一个问题,当然,它在其他浏览器中运行得很好。所以我有一个CSS类。我正在做一个像一个框架,有一个左,中,右的部分,但有三个不同的颜色方案。因此,我不想创建9个不同的类,我使用CSS功能,如下例所示:
.container-header .left { /* Some styles here... */ }
.container-header .left.style1 { /* Some styles here... */ }
.container-header .left.style2 { /* Some styles here... */ }
.container-header .left.style3 { /* Some styles here... */ }
.container-header .middle { /* Some styles here... */ }
.container-header .middle.style1 { /* Some styles here... */ }
.container-header .middle.style2 { /* Some styles here... */ }
.container-header .middle.style3 { /* Some styles here... */ }
.container-header .right { /* Some styles here... */ }
.container-header .right.style1 { /* Some styles here... */ }
.container-header .right.style2 { /* Some styles here... */ }
.container-header .right.style3 { /* Some styles here... */ }
一切都很完美,然后我打开了I浏览器。在我的HTML中,有一个简单的结构,如下所示:
<div class="container-header">
<div class="left style1"></div>
<div class="middle style1"></div>
<div class="right style1"></div>
</div>
问题是IE有自己的意见,在代码中的最后一个元素之前跳过所有的CSS样式。我的意思是,left style1和Midstyle1正在使用right style1样式进行渲染。我不知道如何使IE阅读之前的样式,而不是跳过它们。如果有人写他的意见,我会很高兴的。谢谢:)
PP:对不起,我的英语不好。:(
发布于 2012-09-24 08:15:24
您的页面可能处于古怪模式,因此需要向页面中添加一个doctype声明,以使其在标准模式下呈现。
IE中的古怪模式有一个错误,导致它只读取类选择器链中的最后一个类,因此它处理您的规则如下:
.container-header .left { /* Some styles here... */ }
.container-header .style1 { /* Some styles here... */ }
.container-header .style2 { /* Some styles here... */ }
.container-header .style3 { /* Some styles here... */ }
.container-header .middle { /* Some styles here... */ }
.container-header .style1 { /* Some styles here... */ }
.container-header .style2 { /* Some styles here... */ }
.container-header .style3 { /* Some styles here... */ }
.container-header .right { /* Some styles here... */ }
.container-header .style1 { /* Some styles here... */ }
.container-header .style2 { /* Some styles here... */ }
.container-header .style3 { /* Some styles here... */ }
这也会影响标准模式下的IE6,而标准模式的唯一解决办法是为您的HTML元素分配唯一的类。另请参阅this answer以获得插图。
顺便提一句,这不是继承错误,而是级联错误(或者更确切地说,是选择器解析错误导致了糟糕的级联)。
https://stackoverflow.com/questions/12568902
复制相似问题