博客列表 >常用的两种伪类选择器

常用的两种伪类选择器

P粉932932019
P粉932932019原创
2022年07月08日 10:07:59634浏览

一、结构伪类选择器

  1. <style>
  2. .catelist{
  3. margin: 20px;
  4. }
  5. /* 结构伪类选择器 */
  6. .item:nth-of-type(2){
  7. color: red;
  8. }
  9. .item:nth-of-type(2n){
  10. background-color: rgb(227, 227, 227);
  11. }
  12. .item:nth-last-of-type(1){
  13. color: blue;
  14. }
  15. .item:nth-last-of-type(3){
  16. color: rgb(15, 241, 15);
  17. }
  18. </style>
  19. <ol class="catelist">
  20. <li class="item">item1</li>
  21. <li class="item">item2</li>
  22. <li class="item">item3</li>
  23. <li class="item">item4</li>
  24. <li class="item">item5</li>
  25. <li class="item">item6</li>
  26. <li class="item">item7</li>
  27. <li class="item">item8</li>
  28. </ol>

二、状态伪类选择器

  1. <style>
  2. /* 状态伪类选择器 */
  3. input:focus{
  4. background-color: aquamarine;
  5. border: 1px dashed gray;
  6. }
  7. input:disabled{
  8. color: red;
  9. border: none;
  10. }
  11. button{
  12. width: 150px;
  13. height: 30px;
  14. border: none;
  15. margin-bottom: 10px;
  16. background-color: greenyellow;
  17. }
  18. button:hover{
  19. background-color: red;
  20. cursor: pointer;
  21. color: #fff;;
  22. }
  23. </style>
  24. <div class="regist">
  25. <form action="check.php" method="post">
  26. <fieldset>
  27. <legend>用户注册</legend>
  28. <label>用户名:<input type="text" /></label>
  29. <label>
  30. 性别:<input type="radio" name="sex" value="1" checked />
  31. <input type="radio" name="sex" value="0" />
  32. </label>
  33. <label>
  34. 警告:<input type="text" value="一旦注册不可修改" disabled />
  35. </label>
  36. <button>提 交</button>
  37. </fieldset>
  38. </form>
  39. </div>

声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议