博主信息
博文 13
粉丝 0
评论 0
访问量 10937
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
选择器权重~伪类
shooter
原创
748人浏览过

权重参考值

  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. }
批改老师:PHPzPHPz

批改状态:合格

老师批语:
本博文版权归博主所有,转载请注明地址!如有侵权、违法,请联系admin@php.cn举报处理!
全部评论 文明上网理性发言,请遵守新闻评论服务协议
0条评论
作者最新博文
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号

  • 登录PHP中文网,和优秀的人一起学习!
    全站2000+教程免费学