两个css文件定义相同的类 [英] Two css files defining same class
问题描述
如果我有两个css文件:
If I have two css files:
文件1:
.colorme
{
background-color:Red;
}
档案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文件,更准确地包括)。注意,它是per-property,但是,如果加载2个定义与不同的属性,结果将是组合。如果一个属性在第一个和第二个,这个属性上的最后胜利。
The one loaded last (or as David points out, more accurately included last) 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.
确保其中使用last / wins的唯一方法是包括<$ c
The only way to ensure which is used last/wins is including the <link>
elements in the order you want in the page.
对于属性,下面是一个例子:
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
等效于:
.class1 { color: blue; border: solid 1px blue; padding: 4px; margin: 2px; }
这篇关于两个css文件定义相同的类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!