很多情况下,你会使用 CSS 库,这些库可能会意外覆盖掉你自己的 CSS。所以当你需要确保某元素具有指定的 CSS 时,你可以使用
!important
。
1 <style>
2 body {
3 background-color: black;
4 font-family: Monospace;
5 color: green;
6 }
7 #orange-text {
8 color: orange;
9 }
10 .pink-text {
11 color: pink !important;
12 }
13 .blue-text {
14 color: blue;
15 }
16 </style>...
17 <h1 id="orange-text" class="pink-text blue-text" style="color: white">Hello World!</h1>
Hello World!是粉色的