<link href="style1.css" rel="stylesheet" type="text/css">
<link href="style2.css" rel="stylesheet" type="text/css">
在 style1 中,假设我将颜色声明为白色:
.box{
color:#fff;
}
在 style2 中,我声明它是黑色的。
.box{
color:#000;
}
为什么 style1 优先?
最佳答案
如果两个 CSS 包含完全相同的 css 类,最后加载的 CSS 文件将被视为扩展器 - 这意味着您必须将 !important
放在 css 中最后定义的样式之后。
示例
样式1
.box{
color:#fff;
}
风格2
.box{
color:#000 !important;
}
这样,Style2 将始终取代 Style1。
关于html - 为什么 CSS include 的顺序不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7020530/