There are many selectors in CSS, such as class selectors, tag selectors, ID selectors, etc. The priority order of different selectors is also different. Today I will talk to you about the priority of CSS selectors. Friends in need can refer to the order, and the use of !important. I hope it will be useful to you.
1. !important indicates the highest priority . IE6 browser does not recognize !important .
Example:
Under normal circumstances, the style written below has a higher priority than the style above
demo1{ color:red; color:green; /*绿色的优先级高于红色,所有浏览器都会显示绿色*/ }
If !important is added, its priority will be higher. IE6 is relatively stupid and I don’t know it.
demo2 { color:red !important; /*除了ie6,其他浏览器会认为红色优先级高,显示红色字体*/ color:green; /*ie6浏览器则顺序读取css所以显示绿色*/ }
But note that ie6 does not recognize the priority of !important, but it does not mean that ie6 does not recognize the style attribute with !important.
demo3{ color:red; color:green !important; /*包括ie6,所有浏览器都显示绿色字体,ie6只是不认识优先级罢了*/ }
2. CSS (Cascading Style Sheets) cascading style sheets. In practical applications, there are generally three cascading methods.
Priority: Inline style sheet (inside the tag) > Embedded style sheet (in the current file) > External style sheet (in the external file).
1. External style (applied to multiple web pages)
In the external style sheet, the CSS code is stored as a separate file. For example, the style.css file contains all styles. External cascading in HTML is introduced using the tag or the @import statement.
The sample code is as follows:
<link rel="stylesheet" href="style.css" type="text/css" /> //link 链接 @import url("style.css"); //@import 导入
The similarities and differences between @import and @import can be found in its article
2. Inline (applied to the current page)
The CSS code of the portal website is usually embedded, which is commonly known as inline style (Inline Style), which uses the