ASCII码 ASCII码

CSS:选择器:伪类-复习(first-of-type,nth-last-of-type,nth-of-type(2n + 1):hover)

发布于:2022-05-10 10:44:17  栏目:技术文档
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>选择器:伪类</title>
  8. </head>
  9. <body>
  10. <!--
  11. 伪类:
  12. 1.结构伪类:根据元素位置获取元素
  13. 2.状态伪类:根据状态来获取元素 -->
  14. <ul class="list">
  15. <li class="first">item1</li>
  16. <li>item2</li>
  17. <li>item3</li>
  18. <li>item4</li>
  19. <li>item5</li>
  20. <li>item6</li>
  21. <li>item7</li>
  22. <li>item8</li>
  23. </ul>
  24. <style>
  25. /* .list >:first-child{
  26. background-color: red;
  27. } */
  28. /* .list >p:first-of-type{
  29. background-color: yellow;
  30. }
  31. .list .first{
  32. background-color: lightgreen;
  33. } */
  34. /* .list >li:nth-of-type(3){
  35. background-color: lightblue;
  36. } */
  37. /* .list >li:nth-last-of-type(3){
  38. background-color: lightblue;
  39. } */
  40. .list > :nth-of-type(2n){
  41. background-color: lightblue;
  42. }
  43. .list > :nth-of-type(2n + 1){
  44. background-color: red;
  45. }
  46. .list > :nth-of-type(2n + 1):hover{
  47. background-color: white;
  48. }
  49. </style>
  50. </body>
  51. </html>
相关推荐
阅读 +