瀏覽器預設樣式不一致(User Agent Stylesheet 差異),Reset 目的是建立一致的跨瀏覽器基準線。
/* 極簡版 - 不推薦生產環境 */
* {
margin: 0;
padding: 0;
}
/* Eric Meyer Reset 2.0 精簡版 */
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center, dl, dt, dd, ol, ul, li,
fieldset, form, label, legend, table, caption,
tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed,
figure, figcaption, footer, header, hgroup,
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
font: inherit;
vertical-align: baseline;
}
缺點:破壞表單元素原生樣式、效能差、需大量覆寫。
sup, sub, blockquote)安裝:npm install normalize.css → @import 'normalize.css';
/* Josh Comeau Modern CSS Reset 精簡版 */
*, *::before, *::after {
box-sizing: border-box;
}
* {
margin: 0;
}
html, body {
height: 100%;
}
body {
line-height: 1.5;
-webkit-font-smoothing: antialiased;
}
img, picture, video, canvas, svg {
display: block;
max-width: 100%;
}
input, button, textarea, select {
font: inherit;
}
p, h1, h2, h3, h4, h5, h6 {
overflow-wrap: break-word;
}
#root, #__next {
isolation: isolate;
}
專案類型 → 推薦方案
├─ 新專案、現代技術棧、團隊熟悉 CSS 變數 → Modern CSS Reset
├─ 需支援 IE11、大型既有專案遷移 → Normalize.css
├─ 極簡專案、原型驗證 → * { margin:0; padding:0; box-sizing:border-box; }
└─ Email 模板、極度受限環境 → 內聯樣式 + 精簡重置
/* project-reset.css */
:root {
/* 設計系統 Tokens */
--color-text: #1a1a1a;
--color-bg: #ffffff;
--font-sans: "Noto Sans TC", system-ui, sans-serif;
--line-height: 1.6;
}
/* 1. 盒模型統一 */
*, *::before, *::after {
box-sizing: border-box;
}
/* 2. 移除預設間距 */
* {
margin: 0;
padding: 0;
}
/* 3. 基礎排版 */
html {
font-size: 16px;
-webkit-text-size-adjust: 100%;
}
body {
min-height: 100vh;
font-family: var(--font-sans);
font-size: 1rem;
line-height: var(--line-height);
color: var(--color-text);
background-color: var(--color-bg);
text-rendering: optimizeLegibility;
}
/* 4. 媒體元素預設 */
img, picture, video, canvas, svg {
display: block;
max-width: 100%;
height: auto;
}
/* 5. 表單元素字體繼承 */
input, button, textarea, select {
font: inherit;
color: inherit;
}
/* 6. 文字換行優化 */
p, h1, h2, h3, h4, h5, h6 {
overflow-wrap: break-word;
hyphens: auto;
}
/* 7. 連結無障礙 */
a:not([class]) {
text-underline-offset: 0.1em;
}
a:focus-visible {
outline: 2px solid currentColor;
outline-offset: 2px;
}
reset.css 或 _reset.scss