example_of_css_2.html 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>CSS - 优先级</title>
  6. <!-- 一般情况下网站的首页会使用内部样式表 - 首页正常渲染 -->
  7. <!-- 其他的页面可以共享一个或多个外部样式表 - 代码复用/减少对带宽和流量的使用 -->
  8. <link rel="stylesheet" href="css/style.css">
  9. <!-- 不冲突的样式会叠加,有冲突的样式遵循三条原则 -->
  10. <!-- 1. 就近原则 -->
  11. <!-- 2. 具体性原则(ID > 类 > 标签 > 通配符) -->
  12. <!-- 3. 重要性原则 -->
  13. <style>
  14. #h1 { color: blue; }
  15. .h1 { color: green !important; }
  16. .h1 {
  17. color: pink !important;
  18. border: 5px dotted #FFA500;
  19. width: 300px;
  20. height: 80px;
  21. line-height: 80px;
  22. text-align: center;
  23. margin-top: 50px;
  24. padding: 100px 100px;
  25. }
  26. h1 { color: red; }
  27. </style>
  28. </head>
  29. <body>
  30. <!-- 内嵌样式表 / 行内样式表 -->
  31. <h1 class="a big" style="background-color: #ffff00; font-family: 'courier new'; text-align: center;">Hello, world!</h1>
  32. <!-- Box Model(盒子模型)-->
  33. <h1 class="h1" id="h1">Goodbye world!</h1>
  34. </body>
  35. </html>