Blogger Information
Blog 26
fans 0
comment 1
visits 10496
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
1. 实例演示权重的原理与计算方式
P粉751989631
Original
731 people have browsed it

实例演示权重的原理与计算方式

选择器权重在CSS中用3个正整数表示,权重的规则:
1.实体标记:id,class,tag
2.排列顺序:id,class,tag
3.记数方式:选择器中有实体记数量

权重的计算方式:

  1. header.top h1.title div#active{color:red;}

上述中的权重计算如下:

  1. id = #active = 1
  2. class = .top; .title =2
  3. tag = header;h1;div =3
  4. 权重=(123

实例演示结构伪类,通过位置关系匹配子元素

1.用伪类匹配第1个
.list > li:nth-of-type(1) { background-color: lightgreen; }

用伪类匹配第1个

2.快速获取第1个和最后一个: 语法糖:

  1. .list > li:first-of-type {
  2. background-color: lightgreen;
  3. }
  4. .list > li:last-of-type {
  5. background-color: lightgreen;
  6. }

快速获取第1个和最后1个

3.只获取前3个
.list > li:nth-of-type(-1n + 3) { background-color: lightgreen; }
只获取前3个

Correcting teacher:PHPzPHPz

Correction status:qualified

Teacher's comments:完成的不错
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post