简体   繁体   English

即使使用相同的选择器,外部样式表仍将覆盖内部样式表

[英]External stylesheets are overriding internal, even with the same selector

I have 2 pages (SignIn and PasswordReset) and an external CSS file (named MainStyleSheet.css). 我有2个页面(SignIn和PasswordReset)和一个外部CSS文件(名为MainStyleSheet.css)。 I have some HTML elements in my pages which all have a class (named ab-control-container ). 我的页面中有一些HTML元素,它们都有一个类(名为ab-control-container )。 In both pages, I need to override some stylesheet for the class ab-control-container . 在两个页面中,我都需要为ab-control-container类重写一些样式表。

The problem which is confusing me is that in the in the first page (SignIn), internal stylesheets are overriding the external as I excepted, but in the second page (PasswordReset) those internal stylesheets which is as the same as stylesheets of the first page, are NOT overriding external. 让我感到困惑的问题是,在第一页(SignIn)中,内部样式表覆盖了我所例外的外部样式,但是在第二页(PasswordReset)中,这些内部样式表与第一页的样式表相同,不覆盖外部。

this is what Chrome Inspect Element tool shows: first page: 这是Chrome Inspect Element工具显示的内容:第一页:

第一页 and the second page: ! 第二页:

在此处输入图片说明 What is the problem and Why? 有什么问题,为什么?

internal stylesheets are overriding the external as I excepted 内部样式表覆盖了我所排除的外部样式表

<style> elements do not have priority over <link> ed stylesheets in the cascade. 在层叠中, <style>元素没有优先于<link> ed样式表。

You might be getting confused with style attributes (which have higher specificity than any ruleset). 您可能会对style 属性 (比任何规则集具有更高的特异性)感到困惑。

When two rulesets have selectors with equal specificity (and these do, they selectors are completely identical!) then later ones override earlier ones. 当两个规则集有相等的特异性选择(这些事,他们选择是完全一致的!),那么后来者超越前面的人。

You need to change the order the stylesheets are loaded in, or the specificity of the selectors. 您需要更改样式表的加载顺序或选择器的特异性。

See the cascade for more details. 有关更多详细信息,请参见级联

Seems like PasswordReset has the internal CSS much earlier in the code (line 19) than SignIn (line 621). 似乎PasswordReset在代码(第19行)中具有比SignIn (第621行)更早的内部CSS。 From that i assume that the external stylesheet is referenced somewhere between those positions, which produces a different order of rules (with the later ones overwriting preceding ones). 因此,我假设外部样式表是在这些位置之间的某个地方引用的,这会产生不同顺序的规则(后面的规则会覆盖前面的规则)。

Move the internal CSS in PasswordReset further down, below the line that references the external stylesheet, this should fix it. PasswordReset的内部CSS进一步移到引用外部样式表的行下方,这应该可以对其进行修复。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM