html - 为什么 CSS include 的顺序不起作用?

标签 html css templates

<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/

相关文章:

c++ - std::max 函数 VS '>' 运算符中 int 和 long long int 之间的最大值

html - 在 list-style 为 none 时,将 HTML 列表中的文本缩进换行

javascript - 扩大 UL 的过渡效应

c++ - 关于两阶段查找和这个指针

javascript - 打开可折叠时将网站的其余部分向下移动

javascript - 隐藏包含特定文本的 div

C++ 可变参数模板和隐式转换

php - 运行查询后如何重定向到另一个页面

html - 在鼠标悬停之前为伪元素保留空间

html - 浮球 Canvas