编程知识 cdmana.com

Three characteristics of CSS and weight superposition

Layering

1. Style conflict , The principle to follow is Nearby principle , Which style is closer to the structure , Just follow the pattern

2. The style doesn't conflict , It doesn't stack

inheritance

Child tags inherit some of the styles of the parent tags , Such as text color and font size

priority

When the same element specifies multiple selectors , There will be priorities .

Same selector , Then perform cascading

Selectors are different , According to the selector weight

The selector weights are shown in the table below :

Selectors

Selector weight

To inherit or *

0,0,0,0

Element selector

0,0,0,1

Class selectors , Pseudo class selector

0,0,1,0

ID Selectors

0,1,0,0

Inline style style=""

1,0,0,0

!important Important

infinity

example :

Weight superposition : If it's a composite selector , Then there will be a weight stack , You need to calculate the weight .

div ul li ------> 0,0,0,3

.nav ul li ------> 0,0,1,2

a:hover -----—> 0,0,1,1

.nav a ------> 0,0,1,1

版权声明
本文为[Waves Lala]所创,转载请带上原文链接,感谢

Scroll to Top