10.选择器.html 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. */
  11. * {
  12. list-style: none;
  13. text-decoration: none;
  14. box-sizing: border-box;
  15. }
  16. /* 标签选择器 */
  17. div {
  18. width: 200px;
  19. height: 200px;
  20. background: #00f;
  21. }
  22. /* id选择器 */
  23. #part1 {
  24. background-color: red;
  25. }
  26. /* class选择器 */
  27. .part2 {
  28. background-color: #ff0;
  29. }
  30. /* 包含选择器 后代选择器 */
  31. #part1 span {
  32. color: #ff0;
  33. font-size: 30px;
  34. }
  35. /* 伪类选择器
  36. :hover 滑过
  37. :first-child 第一个子类
  38. :last-child 最后一个子类
  39. :nth-child(n) 自定义子类
  40. even 偶数 2n
  41. odd 奇数 2n+1
  42. */
  43. ul li:first-child {
  44. color: red;
  45. }
  46. /*
  47. 伪元素选择器
  48. ::after/::before {
  49. content:''
  50. }
  51. */
  52. p::after {
  53. content: "还在上课";
  54. color: #00f;
  55. }
  56. p::before {
  57. content: "中午了";
  58. color: #f0f;
  59. }
  60. /* 子类选择器 用>连接 */
  61. #part1>span {
  62. color: #0ff;
  63. }
  64. /* 群组选择器 用,连接 */
  65. p,h1 {
  66. color: pink;
  67. }
  68. /* 属性选择器 */
  69. img[alt='www'] {
  70. width: 200px;
  71. height: 200px;
  72. }
  73. /*
  74. + 相邻选择器
  75. */
  76. h3+h4 {
  77. color: red;
  78. }
  79. /*
  80. ~ 兄弟选择器
  81. */
  82. h2 ~ h3 {
  83. color: purple;
  84. }
  85. h2 ~ h5 {
  86. color: purple;
  87. }
  88. /*
  89. !important 优先级:正无穷
  90. */
  91. b {
  92. color: red !important;
  93. }
  94. b {
  95. color: purple;
  96. }
  97. </style>
  98. </head>
  99. <body>
  100. <div id="box">
  101. <div id="part1" class="part2">
  102. <span> hello </span>
  103. </div>
  104. <b>哇哇哇哇哇哇哇哇</b>
  105. <p>今天星期六</p>
  106. <ul id="mode1">
  107. <li>你好</li>
  108. <li>你好</li>
  109. <li>你好</li>
  110. </ul>
  111. <ul id="mode2">
  112. <li>你好</li>
  113. <li>你好</li>
  114. <li>你好</li>
  115. </ul>
  116. <ul id="mode3">
  117. <li>你好</li>
  118. <li>你好</li>
  119. <li>你好</li>
  120. </ul>
  121. <a href="">你好</a><a href="">你好</a><a href="">你好</a>
  122. <h1>哈哈哈</h1>
  123. <img src="../1.html/images/1.png" alt="www">
  124. <h2>哈哈哈2</h2>
  125. <h3>哈哈哈3</h3>
  126. <h4>哈哈哈4</h4>
  127. <h5>哈哈哈5</h5>
  128. </div>
  129. </body>
  130. </html>