简体   繁体   English

CSS命令和Internet Explorer

[英]CSS order and Internet explorer

I have a problem when loading dinamycally CSS into IE. 将dinamycally CSS加载到IE中时遇到问题。

I have different CSS files and I need to add these files to the head in a certain order. 我有不同的CSS文件,我需要按特定顺序将这些文件添加到头部。 For Example I have a customer file that should have always the highest priority and I have to include at the beginning when reading the customer information. 例如,我有一个始终具有最高优先级的客户文件,我必须在阅读客户信息时包括在内。

So I have something like: 所以我有类似的东西:

< head >  
     < link rel: "stylesheet",
        type: "text/css",
        href: "StartingCSS.css">  
     < link rel: "stylesheet",
        type: "text/css",
        href: CSSclient.CSS>  
< /head >  

In a certain moment I have to include to the head another css file specific for another module and using prototype and JavaScript I include this file the first one in the head, so I have something like this: 在某个时刻,我必须在头部包含另一个特定于另一个模块的css文件,并使用原型和JavaScript我将头文件中的第一个包含在这个文件中,所以我有这样的东西:

< head >      
     < link rel: "stylesheet",
        type: "text/css",
        href: "MyModule.css">  
     < link rel: "stylesheet",
        type: "text/css",
        href: "StartingCSS.css">  
     < link rel: "stylesheet",
        type: "text/css",
        href: CSSclient.CSS>  
< /head >  

In a normal browser, like chrome or FF the CSSclient file still has the highest priority because is the last one in the document but in IE the last file inserted is getting the power. 在普通的浏览器中,如chrome或FF,CSSclient文件仍具有最高优先级,因为它是文档中的最后一个,但在IE中,插入的最后一个文件正在获得权力。

Someone has a great idea for me? 有人对我有好主意吗? :) :)

Thanks a lot, José 非常感谢,José

The order in which you load your CSS files has very little influence in how styles are applied. 加载CSS文件的顺序对样式的应用方式影响很小。 What styles are applied to a certain element is determined by the specificity of the selectors used in the CSS rule. 应用于某个元素的样式取决于CSS规则中使用的选择器的特殊性。 A higher specificity overrules a lower specificity, even if the style with the lower specificity is declared later. 更高的特异性优先于较低的特异性,即使稍后宣布具有较低特异性的样式。

The specificity can be seen as a combination of four digits in the form (a,b,c,d) where a takes precedences over b and b over c and c over d. 特异性可以看作是 (a,b,c,d)形式的四位数的组合,其中a优先于b,b优先于c,c优于d。 So (0,0,0,2) has a higher specificity than (0,0,0,1) and (0,0,1,0) has a higher specificity than (0,0,0,2). 因此(0,0,0,2)具有比(0,0,0,1)更高的特异性,并且(0,0,1,0)具有比(0,0,0,2)更高的特异性。

The order of style declaration (ie the order in which style sheets are loaded) is only important if selectors are used with exactly the same specificity. 样式声明的顺序(即加载样式表的顺序)仅在选择器具有完全相同的特异性时才重要。


Update: 更新:

Updated the link with correct URL. 使用正确的URL更新了链接。

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

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