在 IE 10 之前,開發者常用「條件註解」針對特定 IE 版本載入修補樣式表:
<!--[if IE 6]>
<link rel="stylesheet" href="ie6.css">
<![endif]-->
<!--[if IE 7]>
<link rel="stylesheet" href="ie7.css">
<![endif]-->
這些註解只在 IE 中生效,其他瀏覽器視為普通註解忽略。優點是不汙染主樣式表;缺點是維護成本高、增加 HTTP 請求、IE 10+ 已移除支援。
@supports 判斷功能支援度,避免瀏覽器嗅探。flexibility (Flexbox)、css-vars-ponyfill 等 Polyfill;建置流程用 autoprefixer 自動補齊廠商前綴。<script> 動態載入,僅在缺乏支援時下載:if (!CSS.supports('display', 'grid')) {
const script = document.createElement('script');
script.src = 'grid-polyfill.js';
document.head.appendChild(script);
}
legacy-ie.css,並在建置時透過 postcss-custom-properties 等工具自動處理。html 標籤加類名法(如 <html class="ie9">)配合 JS 偵測,避免條件註解。隨著 IE 逐漸退出歷史舞台,條件註解已完成歷史使命。現代專案應採用「特性偵測 + Polyfill + 自動化建置」策略,以最小成本支援舊環境,同時享受現代 CSS 的表達力與維護性。