选择器的优先级.html 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. /* div {
  9. color: aqua !important;
  10. } */
  11. #word {
  12. color: #ff0;
  13. }
  14. ul li:first-child{
  15. color: red;
  16. }
  17. /* .text {
  18. color: blue;
  19. } */
  20. ul li:first-child {
  21. color: #ff0;
  22. }
  23. div {
  24. color: aquamarine;
  25. }
  26. </style>
  27. </head>
  28. <body>
  29. <div class="text" style="color: #ff0;">这个文字</div>
  30. <!-- <ul>
  31. <li class="text">1</li>
  32. <li>2</li>
  33. <li>3</li>
  34. <li>4</li>
  35. </ul> -->
  36. <!--
  37. css选择器优先级及权重:
  38. !important >内联样式(style)> id选择器 >类选择器(class)= 伪类选择器 = 属性选择器 > 标签选择器=伪元素选择器>通配符选择器
  39. 权重: 正无穷 1,0,0,0 0,1,0,0 0,0,1,0 0,0,0,1 0,0,0,0
  40. -->
  41. </body>
  42. </html>