/* 單行註釋 */
/*
多行註釋
可跨行、嵌套說明
*/
/*
文件頭部版權/作者/版本信息
@file: reset.css
@author: Team
@version: 2.1.0
*/
注意: CSS 無行內註釋(//),構建工具(PostCSS/Less/Sass)會在編譯階段剝離,生產環境不輸出。
| 目標 | 選擇器 Hack | 屬性 Hack | 原理 |
|---|---|---|---|
| IE6 | * html .box { } | _margin: 10px; | 通配符解析差異、屬性前綴識別 |
| IE7 | *:first-child+html .box { } | *margin: 10px; | 鄰接選擇器、屬性前綴 |
| IE8/9 | .box { property: value\9; } | \9 後綴 | 屬性值結束符解析差異 |
| IE10+ | @media -ms-high-contrast { .box { } } | — | 媒體查詢特性檢測 |
| IE6/7 隱藏 | html>body .box { } | — | 子選擇器 IE6/7 不支持 |
| IE Mac 隱藏 | /*\*/ * html .box { } /**/ | — | 註釋解析差異 |
/* 僅支持 Grid 的瀏覽器執行 */
@supports (display: grid) {
.layout { display: grid; grid-template-columns: 1fr 1fr; }
}
/* 不支持時的降級 */
@supports not (display: grid) {
.layout { display: flex; flex-wrap: wrap; }
}
<!--[if IE]>
<link rel="stylesheet" href="ie-legacy.css">
<![endif]-->
<!--[if gt IE 8]>
<link rel="stylesheet" href="ie9-plus.css">
<![endif]-->
IE10+ 已移除條件註釋支持,現代瀏覽器視為普通註釋忽略。
<script>
// 檢測關鍵特性
const html = document.documentElement;
if (CSS.supports('display', 'grid')) html.classList.add('has-grid');
if ('IntersectionObserver' in window) html.classList.add('has-io');
</script>
/* CSS 中按能力分發 */
.has-grid .gallery { display: grid; }
.no-grid .gallery { display: flex; }
browserslist 自動補全前綴、降級語法(如 gap → margin、clamp() → 多行媒體查詢)。/* ===================================
模組:按鈕系統 Button System
維護者:@designer @frontend-lead
更新:2024-01-15 v2.3
=================================== */
/* 基礎結構 — 不包含業務色彩 */
.btn {
display: inline-flex;
align-items: center;
justify-content: center;
/* ... */
}
/* 狀態變體 — 使用 BEM 命名 */
.btn--primary { }
.btn--disabled { }
/* 尺寸變體 */
.btn--sm { }
.btn--lg { }
/*
⚠️ 已知問題:iOS Safari 下 line-height 導致文字偏移
相關 Issue: #1234
臨時方案:.btn { line-height: 1.2; }
*/
/*
按鈕組件 - 主要操作按鈕
Markup: <button class="btn btn--primary">...</button>
StyleGuide: components.buttons.primary
*/
.btn--primary { background: var(--color-primary); }
總結: 新項目零容忍 Hack,採用 @supports + browserslist + PostCSS 自動降級;舊項目維護期內隔離 Hack 至單獨文件並標註清理計劃。註釋應服務於團隊協作、自動化文檔、審計追溯三大目標。