/* ❌ 反模式:通配符重置 */
* { margin: 0; padding: 0; }
缺點:
<input>、<button>、<table> 等元素異常,需大量補救npm install normalize.css → @import "normalize.css";/* ===================================
Modern CSS Reset - v1.0
=================================== */
/* 1. 盒模型統一 */
*, *::before, *::after { box-sizing: border-box; }
/* 2. 移除默認邊距(針對性元素) */
body, h1, h2, h3, h4, h5, h6, p,
blockquote, dl, dd, ul, ol,
figure, pre, textarea,
fieldset, legend { margin: 0; }
/* 3. 列表重置(非語義區域) */
ul, ol { list-style: none; padding: 0; }
/* 4. 圖片/媒體流體化 */
img, picture, video, canvas, svg {
display: block;
max-width: 100%;
height: auto;
}
/* 5. 表單元素字體繼承 */
input, button, textarea, select { font: inherit; }
/* 6. 移除鏈接默認下劃線(可選) */
a { text-decoration: none; color: inherit; }
/* 7. 表格邊框合併 */
table { border-collapse: collapse; border-spacing: 0; }
/* 8. 根元素字體大小(rem 基準) */
html { font-size: 62.5%; } /* 1rem = 10px,便於換算 */
/* 9. 平滑滾動 */
html { scroll-behavior: smooth; }
/* 10. 文本渲染優化 */
body {
line-height: 1.5;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-rendering: optimizeLegibility;
}
早期經典方案,現已不再維護,不推薦新項目使用。Normalize.css 繼承並改進了其理念。
normalize.css 作為基礎層reset.css 覆蓋特定需求(如 a { color: inherit; })CSS 失效常見原因排查:未閉合標籤、DOCTYPE、嵌套錯誤、優先級衝突