Blogger Information
Blog 13
fans 0
comment 0
visits 6606
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
选择器权重~伪类
shooter
Original
553 people have browsed it

权重参考值

  1. /* 选择器的权重
  2. id(千) > class(百) > tag(个)
  3. */
  4. /* tag 1个 权重 (0,0,1) */
  5. body {
  6. color: red;
  7. }
  8. /* tag 2个 权重 (0,0,2)*/
  9. body ul {
  10. background-color: aqua;
  11. }
  12. /* class 1个 权重 (0,1,0) */
  13. .list {
  14. background-color: chartreuse;
  15. }
  16. /* id 1个 权重 (1,0,0) */
  17. #b {
  18. background-color: coral;
  19. }

伪类

  1. /* :first-of-type 匹配分组的第一个元素 */
  2. .list > li:first-of-type {
  3. background-color: aqua;
  4. }
  5. /* :last-of-type 匹配分组的最后一个元素 */
  6. .list > :last-of-type {
  7. background-color: darkorange;
  8. }
  9. /* :nth-last-of-type()
  10. 反向匹配第三个元素
  11. a=0
  12. n=n
  13. b=3
  14. a*n+b=3
  15. */
  16. .list > :nth-last-of-type(3) {
  17. background-color: deeppink;
  18. }
  19. /* 获取偶数索引元素
  20. a=2
  21. n=n
  22. b=0
  23. a*n+0=(
  24. 2*0+0=0
  25. 2*1+0=2
  26. 2*2+0=4
  27. 2*3+0=6
  28. ....
  29. 以此类推
  30. )
  31. */
  32. .list > :nth-last-of-type(2n) {
  33. background-color: chartreuse;
  34. }
  35. /* 获取奇数索引元素
  36. a=2
  37. n=n
  38. b=1
  39. a*n+1=(
  40. 2*0+1=1
  41. 2*1+1=3
  42. 2*2+1=5
  43. 2*3+1=7
  44. ....
  45. 以此类推 */
  46. .list > :nth-last-of-type(2n + 1) {
  47. background-color: brown;
  48. }
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!