一 选择器权重

代码

  1. /* 选择器的权重
  2. 1 权重大小:mpottant>id>class>标签 */
  3. /* 标签选择器
  4. (1) 标签选择器权重为个位 1个标签个位为1,每加一个标签个位权重+1 */
  5. /* (2)多个标签选择器中间用“空格链接” */
  6. 实例
  7. /* 这个选择器权重(0.0.1) */
  8. h1 {
  9. color: aqua;
  10. }
  11. /* 这个选择器权重(0.0.2) */
  12. body h1 {
  13. color: blue;
  14. }
  15. /* 这个选择器权重(0.0.3) */
  16. body h1 p {
  17. color: rgb(0, 255, 64);
  18. }
  19. /* CLASS选择器 (1)class选择器权重为十位 1个class为10,每加一个class十位权重 + 10 (2)多个class选择器中间用“空格链接” 标签和class相连用 . */
  20. div.aaaa {
  21. color: blueviolet;
  22. }
  23. .b a {
  24. color: rgb(226, 43, 43);
  25. }
  26. .xx {
  27. color: aqua;
  28. }
  29. .ss.xxx {
  30. color: rgb(15, 131, 64);
  31. }
  32. /*id选择器 (1)id选择器权重为百位 1个id为100,每加一个id百位权重 + 100 */
  33. #dd {
  34. color: rgb(255, 0, 0);
  35. }

示例


伪类选择器

代码

  1. /* 伪类选择器 */
  2. /* 结构伪类 */
  3. /* > 伪类,仍是`class`级, 结构伪类用于获取一组元素,所以和上下文选择器一样,需要设置查询起点(父级),否则从根递归 */
  4. /* 1 nth-of-type 匹配唯一的子元素*/
  5. .list > li:nth-of-type(2n + 2) {
  6. color: aqua;
  7. background-color: blue;
  8. }
  9. /* 偶数算法
  10. (2*0+2=2)
  11. (2*1+2=4)
  12. (2*2+2=6)
  13. (2*3+2=8) */
  14. .list1 > li:nth-of-type(2n + 1) {
  15. color: rgb(38, 0, 255);
  16. background-color: rgb(255, 0, 149);
  17. }
  18. /*奇数算法
  19. (2*0+1=1)
  20. (2*1+1=3)
  21. (2*2+1=5)
  22. (2*3+1=7) */
  23. .list2 > li:nth-of-type(n + 5) {
  24. color: rgb(0, 26, 2);
  25. background-color: rgb(255, 0, 0);
  26. }
  27. /* 从第五个开始计算
  28. (0+0+5=5)
  29. (0+1+5=6)
  30. (0+2+5=7)
  31. (0+3+5=7) */
  32. .list3 > li:nth-of-type(-n + 5) {
  33. color: rgb(0, 26, 2);
  34. background-color: rgb(255, 0, 0);
  35. }
  36. /* 从第五个开始计算倒序 */
  37. /* 从第五个开始计算
  38. (0+0+5=5)
  39. (0-1+5=4)
  40. (0-2+5=3)
  41. (0-3+5=2)
  42. (0-4+5=1)
  43. (0-5+5=0)
  44. */
  45. /* first-of-type 匹配分组第一个子元素*/
  46. .list4 > li:first-of-type {
  47. color: rgb(0, 255, 21);
  48. background-color: rgb(140, 0, 255);
  49. }
  50. /* last-of-type 匹配分组最后一个子元素*/
  51. .list5 > li:last-of-type {
  52. color: rgb(0, 255, 21);
  53. background-color: rgb(140, 0, 255);
  54. }
  55. /* first-of-type 匹配分组倒数第三名*/
  56. .list6 > li:nth-last-of-type(-n + 3) {
  57. color: rgb(0, 255, 21);
  58. background-color: rgb(140, 0, 255);
  59. }

示例


更多相关文章

  1. Android程序在genymotion模拟器上能够成功安装但无法运行,点击app
  2. 选择器权重及伪类选择器练习
  3. css选择器权重、伪类选择器计算方式
  4. 选择器知识汇总
  5. Android开发之实现图片自动滚动显示标签的ViewPager
  6. 打造自己的标签栏
  7. vscode的安装和html语法标签
  8. 图片、链接、列表及表格标签的学习与运用
  9. HTML标签的使用

随机推荐

  1. 说说Java的Comparable 与 Comparator
  2. Prometheus和Grafana监控Nacos
  3. Mysql各种存储引擎对比总结
  4. Go语言开发的Web框架都有哪些?
  5. PMP备考心得
  6. Android学习笔记3:使用日志工具
  7. 堆排序就这么简单
  8. 阻塞队列 BlockingQueue
  9. redis集群教程(二)
  10. 由浅入深,走进Python装饰器-----第五篇: