This time I will bring you a detailed explanation of the use of the CSS cascading mechanism. What are the precautions for using the CSS cascading mechanism? Here are practical cases, let’s take a look.
Why is there a cascading mechanism in css
Because there may be multiple styles in css that affect a certain attribute of the same element at the same time , the cascading mechanism can resolve style conflicts between authors (people who write code), users (people who browse pages) and user agents (generally referred to as browsers).
Each style rule in the cascade has a weight value. When several of the rules take effect at the same time, the rule with the largest weight takes precedence. Generally speaking, the style weight value specified by the author is higher than the user style weight value, and the user style weight value is higher than the client (user agent) weight value. General weight value and object, whether there is! important, specificity is related to position. In the cascading order, the following weight values are from small to large
(1) User agent style
(2) User general style
(3) Author general style
(4) Author important style (!important)
(5) User important style (!important)
(6) If two styles come from the same code, such as both From the author (code), and their style declarations are equally important, they are calculated according to the specificity. The ones with high specificity will cover the
with low specificity (7) If the specificity is also the same, the further back The higher the priority of the style
Why the important styles set by the user have a higher priority than the important styles of the author? The reason for this is to facilitate the user to implement some special requirements, such as adjusting the page font size, etc. .
Calculation of selector specificity
(1) If a declaration appears in the style attribute of an element, then a Counted as 1;
(2)b is equal to the total number of all ID selectors in the selector and
(3)c is equal to all class selectors and attribute selectors in the selector, And the sum of the sum of the pseudo-class selectors
(4) d is equal to the sum of the sum of all label selectors and pseudo-element selectors in the selector
a-b-c-d is the selector Specificity, the comparison order starts from a first, and whoever is greater first will have a higher priority.
Note:
inheritance has the lowest priority and has no specificity
combining characters (eg, >) and The specificity of the universal selector (*) is 0
.box{} /*特异度=0,0,1,0*/ .box p{} /*特异度=0,0,1,1*/ #nav li{} /*特异度=0,1,0,1*/ p:first-line{} /*特异度=0,0,0,2*/ /*特异度=1,0,0,0*/
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the PHP Chinese website!
Recommended reading:
Detailed analysis of webpack style loading
##20 CSS code usage precautions in front-end practical projects
The above is the detailed content of Detailed explanation of the use of CSS cascading mechanism. For more information, please follow other related articles on the PHP Chinese website!

在css中,可用list-style-type属性来去掉ul的圆点标记,语法为“ul{list-style-type:none}”;list-style-type属性可设置列表项标记的类型,当值为“none”可不定义标记,也可去除已有标记。

区别是:css是层叠样式表单,是将样式信息与网页内容分离的一种标记语言,主要用来设计网页的样式,还可以对网页各元素进行格式化;xml是可扩展标记语言,是一种数据存储语言,用于使用简单的标记描述数据,将文档分成许多部件并对这些部件加以标识。

在css中,可以利用cursor属性实现鼠标隐藏效果,该属性用于定义鼠标指针放在一个元素边界范围内时所用的光标形状,当属性值设置为none时,就可以实现鼠标隐藏效果,语法为“元素{cursor:none}”。

在css中,rtl是“right-to-left”的缩写,是从右往左的意思,指的是内联内容从右往左依次排布,是direction属性的一个属性值;该属性规定了文本的方向和书写方向,语法为“元素{direction:rtl}”。

在css中,可以利用“font-style”属性设置i元素不是斜体样式,该属性用于指定文本的字体样式,当属性值设置为“normal”时,会显示元素的标准字体样式,语法为“i元素{font-style:normal}”。

转换方法:1、给英文元素添加“text-transform: uppercase;”样式,可将所有的英文字母都变成大写;2、给英文元素添加“text-transform:capitalize;”样式,可将英文文本中每个单词的首字母变为大写。

在css3中,可以用“transform-origin”属性设置rotate的旋转中心点,该属性可更改转换元素的位置,第一个参数设置x轴的旋转位置,第二个参数设置y轴旋转位置,语法为“transform-origin:x轴位置 y轴位置”。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Linux new version
SublimeText3 Linux latest version

WebStorm Mac version
Useful JavaScript development tools

Dreamweaver CS6
Visual web development tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 Chinese version
Chinese version, very easy to use
