與上篇(ID 34747)核心代碼相同,此處補充測試環境與 DTD 關鍵提示。
若您在其他版本測試過,歡迎反饋結果。
.e { background-color: #FF0000; } /* FF, OP */
html* .e { background-color: #FF00FF; } /* Sa, IE7, OP */
* html .e {
background-color: #000000; /* OP */
*background-color: #0000FF; /* IE7 */
}
* html .e { background-color: #00FFFF; } /* IE6 */
IE7 的解析受 DOCTYPE 影響:若頁面缺少 DOCTYPE 聲明,IE7 會進入 Quirks 模式,從而識別 IE6 專用 Hack(* html .e 無 *property 時的規則)。務必在文檔頂部聲明完整 DOCTYPE,如:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
此技巧適合「少量樣式差異、不想拆檔」的輕量場景。系統級兼容請使用:
ie6.css/ie7.css