針對 IE6、IE7、Firefox 三大陣營的最小化 Hack 組合,掌握核心識別符 *、_、!important 的識別矩陣,秒級寫出精準兼容代碼。
| 特性 | IE6 | IE7 | Firefox |
|---|---|---|---|
*property | ✓ | ✓ | ✗ |
_property | ✓ | ✗ | ✗ |
!important | ✗ | ✓ | ✓ |
background:orange; *background:blue;(IE6 藍,FF 橙)background:green !important; background:blue;(IE7 綠,IE6 藍)background:orange; *background:green;(IE7 綠,FF 橙)background:orange; *background:green !important; *background:blue;
* 和 !important) → 綠*,忽略 !important) → 藍background:orange; *background:green; _background:blue;
*,忽略 _)* 和 _,後者優先級高)順序固定:Firefox 優先 → IE7 次之 → IE6 最後。瀏覽器按序讀取,後寫者覆蓋前者,利用識別符差異實現分叉。
<!--[if IE 6]><link rel="stylesheet" href="ie6.css"><![endif]-->@supports (display: grid) { ... }Hack 終將成為歷史,但維護舊專案時這張表能救命。