博客列表 >结构伪类选择器:分组

结构伪类选择器:分组

霏梦
霏梦原创
2020年06月16日 09:01:00601浏览

- 作者:霏梦

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  6. <title>结构伪类选择器:分组(不区分元素类型)</title>
  7. <style>
  8. /* 分组结构伪类分二步 */
  9. /* 元素按组分 */
  10. /* 在分组中根据索引进行选择、 */
  11. .h3-title span:last-of-type {
  12. background-color: rebeccapurple;
  13. }
  14. /* 在分组中匹配任何一个 */
  15. .h3-title span:nth-of-type(3) {
  16. font-size: 40px;
  17. }
  18. /* 前3个 */
  19. .h3-title span:nth-of-type(-n + 3) {
  20. color: red;
  21. }
  22. /* 最后三个 */
  23. .h3-title span:nth-last-of-type(-n + 3) {
  24. color: blue;
  25. }
  26. </style>
  27. </head>
  28. <body>
  29. <div class="h3-title">
  30. <div class="wsp">我是第1行</div>
  31. <div class="wsp">我是第2行</div>
  32. <div class="wsp">我是第3行</div>
  33. <span class="wsp">我是第4行</span>
  34. <span class="wsp">我是第5行</span>
  35. <span class="wsp">我是第6行</span>
  36. <span class="wsp">我是第7行</span>
  37. <span class="wsp">我是第8行</span>
  38. <span class="wsp">我是第9行</span>
  39. </div>
  40. </body>
  41. </html>
声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议