5.选择器.html 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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>Document</title>
  7. <style>
  8. /* 通配符选择器 匹配全局样式 */
  9. * {
  10. cursor: pointer;
  11. list-style: none;
  12. text-decoration: none;
  13. }
  14. /* 标签选择器
  15. 格式:标签名称{...}
  16. */
  17. div {
  18. width: 500px;
  19. height: 500px;
  20. background: purple;
  21. /* color: aqua; */
  22. text-align: center;
  23. /* line-height: 200px; */
  24. }
  25. div p {
  26. color: #ff0;
  27. }
  28. /*
  29. id选择器:
  30. 在body标签中:<标签 id="名字1"></标签>
  31. 在样式表中:#名字1:{....}
  32. */
  33. #other {
  34. color: #0f0 !important;
  35. }
  36. #other {
  37. color: #00f;
  38. }
  39. /*
  40. 类选择器:
  41. 在body标签中:<标签 class="名字1"></标签>
  42. 在样式表中:.名字1:{....}
  43. */
  44. .vase {
  45. color: #f00;
  46. }
  47. /* 后代选择器/包含选择器 */
  48. div ul {
  49. list-style: none;
  50. }
  51. div ul li {
  52. color: #ff0;
  53. }
  54. /*
  55. 伪类选择器
  56. :hover 鼠标滑过效果
  57. :nth-child() 自定义子元素
  58. odd 2n+1 奇数项
  59. even 2n 偶数项
  60. :first-child 第一个子元素
  61. :last-child 最后一个子元素
  62. */
  63. div ul li:hover {
  64. color: #fff;
  65. /* 鼠标变小手 */
  66. /* cursor: pointer; */
  67. }
  68. div ul li:nth-child(odd) {
  69. color: #0f0;
  70. }
  71. div p:nth-child(3) {
  72. color: #00f;
  73. }
  74. div ul li:last-child {
  75. color: #f00;
  76. }
  77. div ul li:first-child {
  78. color: #f00;
  79. }
  80. .news {
  81. width: 100%;
  82. /* auto 自适应 */
  83. height: auto;
  84. }
  85. /* 群组选择器:由逗号隔开 */
  86. .news span,
  87. i,
  88. b {
  89. color: aqua;
  90. }
  91. .main {
  92. width: 600px;
  93. height: 900px;
  94. background: #00f;
  95. color: #fff;
  96. }
  97. /* 相邻选择器 由+连接 改变的是加号后的标签 */
  98. .main h2+h3 {
  99. color: #f00;
  100. }
  101. .main h1~.aaa {
  102. color: #ff0;
  103. }
  104. /* 兄弟选择器 用~连接 */
  105. .aaa {
  106. width: auto;
  107. height: auto;
  108. }
  109. /* 伪元素选择器
  110. 前 ::before {
  111. content:""
  112. }
  113. 后 ::after {
  114. content:""
  115. }
  116. */
  117. .word::before {
  118. content: "明天下大雪";
  119. color: #f00;
  120. }
  121. .word::after {
  122. content: "在家吃火锅 你们上早八";
  123. color: #0f0;
  124. }
  125. /* 子类选择器 用>连接 */
  126. .main>p {
  127. color: orange;
  128. }
  129. /*
  130. 属性选择器
  131. 格式:标签名[标签属性='xxx']{...}
  132. */
  133. img[alt='www'] {
  134. width: 200px;
  135. height: 200px;
  136. }
  137. </style>
  138. </head>
  139. <body>
  140. <div>
  141. <p>这是第一个选择器</p>
  142. <p id="other">这是第一个选择器2</p>
  143. <p class="vase">这是第一个选择器</p>
  144. <ul>
  145. <li>无序列表1</li>
  146. <li>无序列表2</li>
  147. <li>无序列表3</li>
  148. <li>无序列表4</li>
  149. <li>无序列表5</li>
  150. <li>无序列表6</li>
  151. </ul>
  152. <div class="news">
  153. <span> 我的名字 </span>
  154. <b>叫</b>
  155. <i>图图</i>
  156. </div>
  157. </div>
  158. <div class="main">
  159. <h1>我家住在翻斗花园</h1>
  160. <h2>我上翻斗幼儿园</h2>
  161. <h3>喜羊羊</h3>
  162. <h4>哆啦A梦</h4>
  163. <h5>海绵宝宝</h5>
  164. <div class="aaa">
  165. 4444444
  166. <h5>33333</h5>
  167. </div>
  168. <p class="word">这是一段新文字</p>
  169. <img src="../day1/images/1.jpg" alt="www">
  170. </div>
  171. </body>
  172. </html>