CSS 定义同一个类的两个css文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2417287/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Two css files defining same class
提问by Haroon
If I have two css files:
如果我有两个 css 文件:
File 1:
文件 1:
.colorme
{
background-color:Red;
}
File 2:
文件2:
.colorme
{
background-color:Green;
}
And have included them in a page, which one will take priority? I'm guessing the one that is loaded last? If so is there anyway to ensure which one css file is loaded last?
并将它们包含在一个页面中,哪个优先?我猜最后加载的那个?如果是这样,无论如何要确保最后加载哪一个 css 文件?
回答by Nick Craver
The one loaded last (or as David points out, more accurately includedlast) wins in this case. Note that it's per-property though, if you load 2 definitions with different properties, the result will be the combination. If a property is in both the first and second, the last wins on that property.
在一个最后加载(或大卫指出,更准确地包括最后)在这种情况下获胜。请注意,它是针对每个属性的,如果您加载 2 个具有不同属性的定义,结果将是组合。如果一个财产同时在第一名和第二名中,则最后一个将赢得该财产。
The only way to ensure which is used last/wins is including the <link>
elements in the order you want in the page.
确保最后使用/获胜的唯一方法是<link>
在页面中按照您想要的顺序包含元素。
For the property, here's an example:
对于属性,这是一个示例:
.class1 { color: red; border: solid 1px blue; padding: 4px; } //First .css
.class1 { color: blue; margin: 2px; } //Second .css
is equivalent to:
相当于:
.class1 { color: blue; border: solid 1px blue; padding: 4px; margin: 2px; }