1.选择器.html 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. list-style: none;
  11. /* font-size:30px; */
  12. }
  13. /* 标签选择器 */
  14. div {
  15. width: 200px;
  16. height: 200px;
  17. background: #f00;
  18. }
  19. /* id选择器 */
  20. #word {
  21. color: #00f;
  22. }
  23. /* 类选择器 */
  24. .name {
  25. color: #0f0;
  26. }
  27. /* 包含选择器 后代选择器 */
  28. .name span {
  29. color: #f00;
  30. }
  31. /* 伪类选择器 */
  32. .list1 li:nth-child(2){
  33. color: #f00;
  34. }
  35. .list1 li:first-child{
  36. color: #00f;
  37. }
  38. .list1 li:last-child {
  39. color:#0f0;
  40. }
  41. .list1 li:nth-child(odd) {
  42. color: #ff0;
  43. }
  44. ul li:hover {
  45. color: orange;
  46. }
  47. /* 子类选择器 用>连接 */
  48. .name>span {
  49. color: #00f;
  50. }
  51. /* 群组选择器 用,连接 */
  52. #word,.name {
  53. color:red;
  54. }
  55. /* .name {
  56. color: red;
  57. } */
  58. /* 属性选择器
  59. 写法:
  60. 在body标签中:当前标签的属性里添加xxx(内容)
  61. 在style中:
  62. 标签名[属性="xxx"]{样式...}
  63. */
  64. img[alt="www"] {
  65. width: 200px;
  66. height: 200px;
  67. }
  68. /*
  69. 伪元素选择器
  70. :before :after
  71. 一定要伴随这 content:"要添加的内容"
  72. ::before ::after
  73. :与::的区别
  74. ::使用在css2语法中
  75. :使用在css3语法中
  76. */
  77. .one {
  78. width: 400px;
  79. height: 200px;
  80. background: #ff0;
  81. }
  82. .one:after {
  83. content:"今天下雪了";
  84. color: #f00;
  85. background-color: #0f0;
  86. }
  87. .one:before {
  88. content:"明天周五了";
  89. color: #00f;
  90. }
  91. /* !important */
  92. .list2 li:nth-child(2) {
  93. color: #f00 !important;
  94. }
  95. .list2 li:nth-child(2) {
  96. color: #00f;
  97. }
  98. /* 相邻选择器 用+连接 */
  99. h1+h2 {
  100. color: red;
  101. }
  102. h2+h3 {
  103. color: #00f;
  104. }
  105. /* 兄弟选择器 用~连接 */
  106. h1~h3 {
  107. color: #0f0;
  108. }
  109. h2~h5 {
  110. color: purple;
  111. }
  112. #word~.name{
  113. color: purple;
  114. }
  115. </style>
  116. </head>
  117. <body>
  118. <!--
  119. 标签选择器:
  120. 写法:标签名 {样式}
  121. -->
  122. <div></div>
  123. <p id="word">这是一段文字</p>
  124. <p class="name">我的<span>名字</span></p>
  125. <ul class="list1">
  126. <li>内容1</li>
  127. <li>内容2</li>
  128. <li>内容3</li>
  129. <li>内容4</li>
  130. </ul>
  131. <img src="../day3/images/1.jpg" alt="www">
  132. <div class="one">这是内容一</div>
  133. <ul class="list2">
  134. <li>内容11</li>
  135. <li>内容22</li>
  136. <li>内容33</li>
  137. <li>内容44</li>
  138. </ul>
  139. <h1>标签</h1>
  140. <h2>标签</h2>
  141. <h3>标签</h3>
  142. <h4>标签</h4>
  143. <h5>标签</h5>
  144. </body>
  145. </html>