选择器.html 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>选择器</title>
  6. <style>
  7. /* 新的样式表会覆盖之前的样式表 */
  8. /* 标签选择器 */
  9. /* div {
  10. width: 300px;
  11. height: 300px;
  12. background: #00f;
  13. } */
  14. /* h2 {
  15. color: #ff0;
  16. } */
  17. /*
  18. id 选择器
  19. 在body标签内的 格式:id="名字(英文)"
  20. 在样式表里 格式:#名字{...}
  21. */
  22. #word {
  23. color: #f00;
  24. }
  25. /*
  26. 类选择器
  27. 在body标签中 格式:class="名字(英文)"
  28. 在样式表里 格式:.名字{...}
  29. */
  30. .main {
  31. color: aquamarine;
  32. }
  33. /* 伪类选择器
  34. :hover 划过效果
  35. :first-child 第一个子元素
  36. :last-child 最后一个子元素
  37. :nth-child(数字) 自定义第几个子元素
  38. 偶数项 even 2n
  39. 奇数项 2n+1 odd
  40. */
  41. a:hover {
  42. color: #f00;
  43. }
  44. /* span {
  45. color: #00f;
  46. } */
  47. /* 包含选择器(后代选择器) */
  48. p span {
  49. color: rgb(48, 230, 63);
  50. }
  51. ul li:first-child {
  52. color: #f00;
  53. }
  54. ul li:last-child {
  55. color: #00f;
  56. }
  57. ul li:nth-child(odd) {
  58. color: #ff0;
  59. }
  60. /*
  61. > 子类选择器
  62. */
  63. p>span {
  64. color: #f00;
  65. }
  66. /* 群组选择器: , */
  67. /* p,span,h2,h3 {
  68. color: #f00;
  69. } */
  70. /* 属性选择器
  71. 格式:
  72. 标签名字[属性="属性值"]{...}
  73. */
  74. img[alt="111"] {
  75. width: 200px;
  76. height: 200px;
  77. }
  78. /* 相邻选择器 + */
  79. /* 挨着h1的h2标签 */
  80. /* h1+h2 {
  81. color: #f00;
  82. }
  83. h2+h3 {
  84. color: #00f;
  85. }
  86. h3+h3 {
  87. color: #0ff;
  88. }
  89. h3+h4 {
  90. color: #ff0;
  91. }
  92. h4+h5 {
  93. color: pink;
  94. } */
  95. /* 兄弟选择器 ~ */
  96. h1~h3 {
  97. color: #00f;
  98. }
  99. h1~h5 {
  100. color: red;
  101. }
  102. h1~h2 {
  103. color: #ff0;
  104. }
  105. h5~span {
  106. color: aqua;
  107. }
  108. </style>
  109. </head>
  110. <body>
  111. <div>
  112. 这是一个盒子
  113. <h2>标题</h2>
  114. </div>
  115. <p id="word">这是一段内容这是一段内容</p>
  116. <p class="main">一段新内容一段新内容</p>
  117. <a href="">音乐</a>
  118. <a href="">跳舞</a>
  119. <a href="">书法</a>
  120. <a href="">画画</a>
  121. <a href="">唱歌</a>
  122. <!-- -->
  123. <p>
  124. <span>新的行内元素</span>
  125. <span>新的行内元素</span>
  126. <span>新的行内元素</span>
  127. <span>新的行内元素</span>
  128. <span>新的行内元素</span>
  129. </p>
  130. <ul>
  131. <li>1</li>
  132. <li>2</li>
  133. <li>3</li>
  134. <li>1</li>
  135. <li>2</li>
  136. <li>3</li>
  137. <li>1</li>
  138. <li>2</li>
  139. <li>3</li>
  140. <li>1</li>
  141. <li>2</li>
  142. <li>3</li>
  143. </ul>
  144. <img src="../day1/images/img01.gif" alt="111">
  145. <h1>h1</h1>
  146. <h2>h2</h2>
  147. <h3>h3</h3>
  148. <h3>h3</h3>
  149. <h4>h4</h4>
  150. <h5>h5</h5>
  151. <span>span1</span>
  152. <div>
  153. <span>span2</span>
  154. </div>
  155. <div>
  156. <p>123</p>
  157. </div>
  158. <span>456</span>
  159. <h2>456</h2>
  160. <h3>456</h3>
  161. <span>456</span>
  162. <span>456</span>
  163. </body>
  164. </html>