简体   繁体   English

style.css是否覆盖其他CSS文件类和ID

[英]Does style.css override other CSS file classes and ids

I had a style.css file for my existing web pages. 我现有的网页都有一个style.css文件。 Then I created some new webpages with internal style sheet. 然后,我用内部样式表创建了一些新网页。 But the new pages were not displayed according to the internal style sheets. 但是根据内部样式表未显示新页面。 When I move those pages to a new web application, they work fine. 当我将这些页面移动到新的Web应用程序时,它们可以正常工作。

I also tried to create an external style sheet for new pages with style.css and included that. 我还尝试使用style.css为新页面创建一个外部样式表,并将其包括在内。 However still the new pages were not displayed accordingly. 但是,新页面仍未相应显示。

Can anyone tell me what might be the issue? 谁能告诉我可能是什么问题? Does style.css override the internal style sheet or other css? style.css是否覆盖内部样式表或其他CSS?

No style.css does not override other styles. No style.css不会覆盖其他样式。 CSS decides which styles to apply to an element based on specificity. CSS根据特定性决定要应用于元素的样式。

CSS Specificity is a somewhat large, but important topic. CSS特异性是一个很大但很重要的主题。 Read about it here: 在这里阅读:

CSS Specificity: Things You Should Know CSS特殊性:您应该知道的事情

Edit 编辑

For equal specificity, the last defined style is used. 为了达到相同的特异性,使用了最后定义的样式。

its depend on the precedence and how you are using form example style.css is at the last of all css than it will override or you have used !important 它取决于优先级以及您如何使用示例样式style.css,而不是它将覆盖的所有CSS中的最后一个,或者您已使用!important

Good read 好读

  1. CSS precedence CSS优先级
  2. 6 Assigning property values, Cascading, and Inheritance 6分配属性值,级联和继承
  3. Understanding Style Precedence in CSS: Specificity, Inheritance, and the CascadeCSS precedence 了解CSS中的样式优先级:特异性,继承性和CascadeCSS优先级
  4. Specifics on CSS Specificity CSS特异性的细节

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

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