Blogger Information
Blog 28
fans 0
comment 1
visits 13112
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
css学习之伪类选择器
centos
Original
557 people have browsed it

css学习之伪类选择器


知识点

  1. 效果图
  2. 代码如下
    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. <link rel="stylesheet" href="" />
    9. /* 总结一下 1. 获取指定的某一个: (b) 2, 获取前几个, (-n+b) 3.
    10. 获取指定位置后的全部元素, (n+b) 4. 获取全部偶数(2n/even)或奇数(2n+1/odd)元素
    11. */
    12. <style>
    13. li {
    14. border: 1px solid;
    15. }
    16. /* :nth-of-type()分组匹配,在匹配前将元素分类后再匹配
    17. 没有 > 这个符号会递归选择*/
    18. /* 1.选择第1个 */
    19. .list > :nth-of-type(1) {
    20. background-color: red;
    21. }
    22. /* 用first-of-type实现第一个 */
    23. .list > :first-of-type {
    24. background-color: red;
    25. }
    26. /* 2.选择第二个 */
    27. .list > :nth-of-type(2) {
    28. background-color: green;
    29. }
    30. /* 3.选择最后一个 */
    31. .list > :last-of-type {
    32. background-color: yellow;
    33. }
    34. /* 4.用last-of-type实现选择倒数第二个 */
    35. .list > :nth-last-of-type(2) {
    36. background-color: black;
    37. }
    38. /* 5.选择器数值的属性结构
    39. nth-of-type(参数)
    40. an+b a为系数;n为计数器 从0开始;b是偏移量 也是从0开始;元素的有效编号: 必须从1开始 */
    41. /* 从第四行 1n+4==>n+4*/
    42. .list-small > :nth-of-type(1n + 4) {
    43. background-color: cyan;
    44. }
    45. /* 选择前三行 */
    46. .list-small > :nth-of-type(-n + 3) {
    47. background-color: orange;
    48. }
    49. /* 选择后三行 */
    50. .list-small > :nth-last-of-type(-n + 3) {
    51. background-color: blue;
    52. }
    53. /* 选择偶数行 2n或者even */
    54. .list-small > :nth-of-type(even) {
    55. background-color: lightgreen;
    56. }
    57. /* 选择偶数行 2n+1或者odd */
    58. .list-small > :nth-of-type(odd) {
    59. background-color: rgb(211, 144, 238);
    60. }
    61. </style>
    62. </head>
    63. <body>
    64. <!-- 伪类:类是class -->
    65. <ul class="list">
    66. <li>item1</li>
    67. <li>item2</li>
    68. <li>
    69. item3
    70. <ul class="list-small">
    71. <li>bb1</li>
    72. <li>bb2</li>
    73. <li>bb3</li>
    74. <li>bb4</li>
    75. <li>bb5</li>
    76. <li>bb6</li>
    77. <li>bb7</li>
    78. <li>bb8</li>
    79. <li>bb9</li>
    80. <li>bb10</li>
    81. </ul>
    82. </li>
    83. <li>item4</li>
    84. <li>item5</li>
    85. <li>item6</li>
    86. <li>item7</li>
    87. <li>item8</li>
    88. </ul>
    89. </body>
    90. </html>
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!