07.伪类选择器.html 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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>Document</title>
  8. <style>
  9. /*
  10. 将ul里的第一个li设置为蓝色
  11. */
  12. /*
  13. 伪类(不存在的类,特殊的类)
  14. -伪类用来描述一个元素的特殊状态
  15. 比如:第一个子元素、被点击的元素、鼠标移入的元素……
  16. -伪类一般情况下都是使用“:”开头
  17. :first-child 第一个子元素
  18. :last-child 最后一个子元素
  19. :nth-child() 选中第n个子元素
  20. 特殊值:
  21. n 第n个,n的范围是0到∞(正无穷)
  22. 2n或even 表示选中偶数位的元素
  23. 2n+1或odd 表示选中奇数位的元素
  24. -以上这些伪类都是根据所有的子元素进行排序的
  25. :first-of-type
  26. :last-of-type
  27. :nth-of-type()
  28. -这几个伪类的功能和上述的类似,不同点是它们是在同类型元素中进行排序
  29. -:not() 否定伪类
  30. -将符合条件的元素从选择器中去除
  31. */
  32. /* ul>li:first-child {
  33. color: blue;
  34. } */
  35. /* ul>li:last-child{
  36. color: blue;
  37. } */
  38. /* ul>li:nth-child(2) {
  39. color: blue;
  40. } */
  41. /* ul>li:nth-child(n) {
  42. color: blue;
  43. } */
  44. /* ul>li:nth-child(2n) {
  45. color: blue;
  46. } */
  47. /* ul>li:nth-child(2n+1) {
  48. color: blue;
  49. } */
  50. /* ul>li:first-of-type{
  51. color: blue;
  52. } */
  53. /* ul > li:not(:nth-of-type(3)){
  54. color: blue;
  55. } */
  56. ul > li:not(:nth-child(3)){
  57. color: blue;
  58. }
  59. </style>
  60. </head>
  61. <body>
  62. <ul>
  63. <span>这是一个span</span>
  64. <li>第一个</li>
  65. <li>第二个</li>
  66. <li>第三个</li>
  67. <li>第四个</li>
  68. <li>第五个</li>
  69. </ul>
  70. </body>
  71. </html>