3.选择器.css 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /* 标签选择器 */
  2. div {
  3. color: aqua;
  4. }
  5. /* 标签选择器 */
  6. #choose {
  7. width: 100px;
  8. height: 40px;
  9. background: #f00;
  10. color: #ff0;
  11. }
  12. /* 类选择器 */
  13. .vase {
  14. color: aquamarine;
  15. }
  16. /* 伪类选择器 */
  17. /* :hover 划过
  18. :first-child
  19. :last-child
  20. :nth-child(num)
  21. */
  22. /* :link 点击前的 */
  23. a:link {
  24. background-color: aquamarine;
  25. }
  26. /* :hover 鼠标划过 悬停 */
  27. a:hover {
  28. background-color: #f00;
  29. }
  30. /* :active鼠标点击时 */
  31. a:active {
  32. background: #00f;
  33. }
  34. /* :visited点击后的状态 */
  35. a:visited {
  36. background-color: #ff0;
  37. }
  38. /* 后代选择器(包含选择器) */
  39. /* p span {
  40. color: #f00;
  41. } */
  42. /* > 子类选择器 */
  43. p>span {
  44. color: #00f;
  45. }
  46. /* 群组选择器 */
  47. h1,h2,b {
  48. color: #f00;
  49. }
  50. /* 属性选择器 */
  51. img[alt='111'] {
  52. width: 200px;
  53. height: 200px;
  54. }
  55. /* 相邻选择器 */
  56. /* h4 + h5 {
  57. color: aqua;
  58. } */
  59. /* 兄弟选择器 */
  60. h3 ~ h5 {
  61. color: #f00;
  62. }
  63. /* 伪元素选择器
  64. ::before
  65. ::after
  66. */
  67. #box1 {
  68. width: 200px;
  69. height: 200px;
  70. background: #00f;
  71. color: #000;
  72. }
  73. #box1::before {
  74. content: 'before';
  75. color: #f00;
  76. }
  77. #box1::after {
  78. content: 'after';
  79. color: #ff0;
  80. }
  81. /* 通配符选择器 */
  82. * {
  83. margin: 0;
  84. padding: 0;
  85. }
  86. /*
  87. css选择器的优先级
  88. !important 正无穷
  89. 内联样式(style) 1,0,0,0
  90. id选择器 0,1,0,0
  91. 类选择器(class) = 伪类选择器 = 属性选择器 0,0,1,0
  92. 标签选择器 = 伪元素选择器 0,0,0,1
  93. 通配符选择器 0,0,0,0
  94. */