Blogger Information
Blog 7
fans 0
comment 0
visits 3446
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
实例演示:选择器权重,常用伪类选择器
Original
511 people have browsed it

选择器权重

代码

  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>

效果

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