6.选择器优先级.html 823 B

123456789101112131415161718192021222324252627
  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. p {
  9. color: #f00;
  10. color: #00f;
  11. }
  12. </style>
  13. </head>
  14. <body>
  15. <!--
  16. 选择器的优先级及其权重
  17. !important > 行内样式(内联样式)> id选择器 > 类选择器 = 伪类选择器 = 属性选择器 > 伪元素选择器 = 标签选择器 > 通配符选择器
  18. 权重: 正无穷 1,0,0,0 0,1,0,0 0,0,1,0 0,0,0,1 0,0,0,0
  19. -->
  20. <p style="color: #0f0;">1234</p>
  21. <!--
  22. HTML为什么语义化?
  23. 1.便携开发
  24. 2.方便搜索引擎(SEO)抓取数据
  25. -->
  26. </body>
  27. </html>