选择器权重

代码

  1. <body>
  2. <ul>
  3. <li class="item1">权重(0,1,2)大于(0,1,1),所以背景色显示蓝色,而非橙色</li>
  4. <li class="item1">权重2</li>
  5. <li class="item2" id="weight">权重(1,0,1)大于(0,1,1),所以背景色显示蓝色,而非粉红色</li>
  6. <li class="item2">权重4</li>
  7. <li class="item3">权重5</li>
  8. <li class="item3">权重6</li>
  9. </ul>
  10. <style>
  11. /* id: 千位 , class: 百位 , tag: 个位 */
  12. /* id: 1 , class: 0 , tag: 1 */
  13. /* 权重(1,0,1) */
  14. #weight {background-color: blue;}
  15. /* id: 0 , class: 1, tag: 2 */
  16. /* 权重(0,1,2) */
  17. ul li.item1 {background-color: cyan;}
  18. /* id: 0 , class: 1, tag: 1 */
  19. /* 权重(0,1,1) */
  20. li.item1 {background-color: orange;}
  21. li.item2 {background-color: violet;}
  22. /* id: 0 , class: 0, tag: 1 */
  23. /* 权重(0,0,1) */
  24. li {background-color: green;}
  25. </style>
  26. </body>

效果

常用伪类选择器

代码

  1. <body>
  2. <ul>
  3. <li>item1</li>
  4. <li>item2</li>
  5. <li>item3</li>
  6. <li>item4</li>
  7. <li>item5</li>
  8. <li>item6</li>
  9. <li>item7</li>
  10. <li>item8</li>
  11. <li>item9</li>
  12. <li>item10</li>
  13. <li>item11</li>
  14. <li>item12</li>
  15. <li>item13</li>
  16. <li>item14</li>
  17. </ul>
  18. <style>
  19. /* 匹配第1个 */
  20. li:first-of-type{ color:orange }
  21. /* :nth-of-type(an+b) */
  22. /* 匹配第4个 */
  23. /* a=0,n=[0,1,...], b = 4 */
  24. li:nth-of-type(4){ color:pink }
  25. /* a=-1 */
  26. /* 取前3个 */
  27. li:nth-of-type(-n+3) { background-color: yellow; }
  28. /* 取后3个 */
  29. li:nth-last-of-type(-n+3) { background-color:lightseagreen; }
  30. /* 匹配第9个及之后 */
  31. /* a=1,n=[0,1,...], b = 9 */
  32. li:nth-of-type(n+9){ color:red }
  33. /* 匹配最后1个 */
  34. li:last-of-type{ color: blue }
  35. </style>
  36. </body>

效果

更多相关文章

  1. Android(安卓)---android:autoLink属性
  2. 权重与伪类选择器
  3. 选择器权重及常用伪类
  4. 精准匹配企业采购需求,构建多场景数字化采购管理新模式
  5. android : 如何通过provider向外共享数据
  6. Android中判断Intent是否存在的方法
  7. 三、Android下拉框实现
  8. python 包之 re 正则匹配教程
  9. Android如何根据当前显示配置匹配资源 layout / drawable

随机推荐

  1. python 安装readline 报错:gcc: error: re
  2. 如何在python中播放wav文件?
  3. Python——字符格式化
  4. python2.7练习小例子(十二)
  5. 【Python】 编码,en/decode函数以及print
  6. 第四章 当索引不好用时
  7. 如何从其他dtypes创建一个numpy dtype?
  8. 独立于数据库的MAX()函数在SQLAlchemy中
  9. 使用python api递归计算每个Dropbox文件
  10. Python为8bit深度图像应用color map