Blogger Information
Blog 34
fans 0
comment 0
visits 24459
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
css基础-选择器、权重、伪类选择器
CY明月归
Original
749 people have browsed it

作业

  1. 实例演示选择器权重,并写出详细计算过程
  2. 实例演示常用伪类选择器,并写出参数计算过程

遇到!importent(调试代码)权重失效

id 尽量不用id class tag

权重参考值

  1. .test1.a{
  2. color:green;
  3. }
  4. //class 2个 权重(0,2,0)
  5. #test1{
  6. color: indianred;
  7. }
  8. //id 1个 权重(1,0,0)
  9. li.a#b{
  10. color: lawngreen;
  11. }
  12. //id 1个 class 1个 tag 1个 权重(1,1,1)

伪类练习

  1. .item>li:first-of-type{
  2. background-color:goldenrod;
  3. }
  4. //匹配分组的第一个子元素
  5. .item>li:nth-last-of-type(3){
  6. background-color: rgb(214, 28, 4);
  7. }
  8. //反向匹配分组第三个位置的子元素;匹配一个a=0, n=n, b=3(索引计算起始偏移量, 从 0 开始) an+b=3 所以是倒数第三个位置的子元素
  9. .item>li:last-of-type{
  10. background-color: rgb(25, 168, 68);
  11. }
  12. //匹配分组的最后一个子元素

  1. .item1>li:nth-of-type(2n){
  2. background-color: rgb(165, 214, 28);
  3. }
  4. //获取偶数索引的元素;匹配一组a=[1,-1,2] 这里面a=2 n=n b=0 2n+0=2n n取值(0,1,2,3...)
  5. //因为:nth-of-type(an+b): 计算出来的索引,必须是有效的, 且从 1 开始的正整数
  6. //所以计算出来的是2,4,6,8...即:nth-of-type(2n)是获取偶数索引的元素
  7. .item1>li:nth-of-type(2n+1){
  8. background-color: hotpink;
  9. }
  10. //同上计算方法,计算出来的是1,3,5,7..即:nth-of-type(2n+1)是获取奇数索引的元素

  1. .item1>li:nth-of-type(-n+3){
  2. background-color: khaki;
  3. }
  4. //反选 a=-1 n=n b=3 n取值(0,1,2,3...)
  5. //-n+3即取值 3,2,1 (!!!写成3-n失效!!!)
  6. .item1>li:nth-of-type(n+5){
  7. background-color: khaki;
  8. }
  9. //反选 a=1 n=n b=5 n取值(0,1,2,3...)
  10. //n+3即取值 5,6,7,8...
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