CSS 样式的结果不是我所期望的

The result of CSS styles is not what I expect

我有以下 html 使用 Bootstrap 样式表:<button class="label btn-lg">Save</button> 我对 CSS Specificity rules btn-lg 覆盖标签值的理解( When selectors have an equal specificity value, the latest rule is the one that counts).但是,无论我对 类 使用哪种顺序,标签都会取代 btn-lg

如何使 btn-lg 覆盖标签?

"When selectors have an equal specificity value, the latest rule is the one that counts" 这意味着将应用样式表中最低的 CSS 规则。因此,在您的情况下,.label class 出现在 bootstrap 样式表中的 .btn-lg 之后。

希望对您有所帮助。

"Latest rule" 表示 CSS 文件中的最后一条规则,而不是 class 顺序。

指向同一文件中的规则的链接: https://github.com/twbs/bootstrap/blob/master/dist/css/bootstrap.css#L3491 https://github.com/twbs/bootstrap/blob/master/dist/css/bootstrap.css#L4897