Blogger Information
Blog 19
fans 0
comment 0
visits 5770
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
基本,上下文,伪类(结构,状态)选择器的各种应用
vbokok
Original
355 people have browsed it
  1. /* 基本选择器 */
  2. h2{
  3. color:aqua
  4. }
  5. h2.spring {
  6. color:blue
  7. }
  8. h2#item {
  9. color:red
  10. }
  11. /* 上下文选择器 */
  12. /* 父子选择器 */
  13. ul.list > .ent {
  14. border: thin solid;
  15. }
  16. /* 后代选择器 */
  17. ul.list >.ent .entent {
  18. color:blue
  19. }
  20. /* 兄弟选择器 */
  21. ul.list > .ent.start + * {
  22. background-color: blueviolet;
  23. }
  24. /* 同级选择器 */
  25. ul.list > .ent.cken ~ * {
  26. color: indianred;
  27. }
  28. /* 伪类选择器 */
  29. ul.bord > :first-child {
  30. color: tomato;
  31. }
  32. ul.bord > :last-child {
  33. color: blue;
  34. }
  35. ul.bord > :nth-child(2n + 2) {
  36. color:deeppink
  37. }
  38. /* ! 状态伪类 */
  39. fieldset {
  40. display: inline-grid;
  41. gap: 1em;
  42. border-radius: 10px;
  43. padding: 1em 2em;
  44. color: #666;
  45. background: linear-gradient(to left top, lightcyan, white);
  46. }
  47. fieldset legend {
  48. text-align: center;
  49. }
  50. fieldset input {
  51. padding: 5px;
  52. border: none;
  53. border-bottom: 1px solid #666;
  54. outline: none;
  55. background-color: transparent;
  56. }
  57. /* ---------------------------- */
  58. fieldset :focus {
  59. background-color: lightsalmon;
  60. }
  61. input[type='checkbox']:checked + label {
  62. color: red;
  63. }
  64. button:hover {
  65. cursor: pointer;
  66. opacity: 0.2;
  67. }
  68. <!DOCTYPE html>
  69. <html lang="zh-CN">
  70. <head>
  71. <meta charset="UTF-8">
  72. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  73. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  74. <link rel="stylesheet" href="css/0205selector.css">
  75. <title>Document</title>
  76. </head>
  77. <body>
  78. <!-- 基本选择器 -->
  79. <h2>Hello World</h2>
  80. <h2 class="spring">Hello spring</h2>
  81. <h2 id="item">Hello everybody</h2>
  82. <hr />
  83. <!-- 上下文选择器 -->
  84. <ul class="list">
  85. <li class="ent">实例1</li>
  86. <li class="ent">实例2</li>
  87. <li class="ent">
  88. <ul>
  89. <li class="entent">item1</li>
  90. <li class="entent">item2</li>
  91. <li class="entent">item3</li>
  92. </ul>
  93. </li>
  94. <li class="ent">实例4</li>
  95. <li class="ent start">实例5</li>
  96. <li class="ent ">实例6</li>
  97. <li class="ent cken">实例7</li>
  98. <li class="ent">实例8</li>
  99. <li class="ent">实例9</li>
  100. </ul>
  101. <hr/>
  102. <!-- 伪元素选择器 -->
  103. <ul class="bord">
  104. <li>item1</li>
  105. <li>item2</li>
  106. <li>item3</li>
  107. <li>item4</li>
  108. <li>item5</li>
  109. <li>item6</li>
  110. <li>item7</li>
  111. <li>item8</li>
  112. <li>item9</li>
  113. <li>item10</li>
  114. <li>item11</li>
  115. </ul>
  116. <hr >
  117. <!-- 状态伪类 -->
  118. <form action="">
  119. <fieldset>
  120. <legend>用户注册</legend>
  121. <!-- autofocus: 布尔属性,自动获取焦点 -->
  122. <input type="text" id="username" name="username" placeholder="用户名" required autofocus />
  123. <input type="email" id="email" name="email" placeholder="邮箱" required disabled />
  124. <input type="password" id="password" name="password" placeholder="密码" required />
  125. <!-- 复选框默认是选中状态: checked -->
  126. <div>
  127. <input type="checkbox" id="rem" name="remember" checked />
  128. <label for="rem">记住我</label>
  129. </div>
  130. <button>提交</button>
  131. </fieldset>
  132. </form>
  133. </body>
  134. </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