瀏覽器預設樣式不一致(margin、padding、font-size、list-style 等),導致跨瀏覽器差異。基礎樣式表統一基準,分為兩大流派:
*, *::before, *::after {
box-sizing: border-box; /* 寬高包含 padding + border */
}
body, h1, h2, h3, h4, h5, h6, p, ul, ol, li,
figure, blockquote, dl, dd, pre, form, fieldset, legend, textarea {
margin: 0;
padding: 0;
}
body {
font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
"Noto Sans TC", "Microsoft JhengHei", sans-serif;
font-size: 16px;
line-height: 1.6;
color: #333;
background: #fff;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
ul, ol { list-style: none; }
table { border-collapse: collapse; border-spacing: 0; }
th, td { text-align: left; vertical-align: top; }
img, video, canvas, audio, iframe, embed, object {
display: block;
max-width: 100%;
height: auto;
border: 0;
}
input, button, select, textarea {
font: inherit; /* 繼承字體 */
color: inherit; /* 繼承顏色 */
border: none;
background: none;
border-radius: 0; /* 移除 iOS 預設圓角 */
-webkit-appearance: none; /* 移除原生外觀 */
}
button, input[type="submit"], input[type="button"] {
cursor: pointer;
}
:focus-visible {
outline: 2px solid #007bff;
outline-offset: 2px;
}
article, aside, details, figcaption, figure, footer, header,
main, menu, nav, section, summary { display: block; }
h1, h2, h3, h4, h5, h6 { font-weight: 600; line-height: 1.3; }
h1 { font-size: 2.5rem; }
h2 { font-size: 2rem; }
h3 { font-size: 1.5rem; }
h4 { font-size: 1.25rem; }
h5 { font-size: 1rem; }
h6 { font-size: 0.875rem; }
a { color: inherit; text-decoration: none; }
a:hover { text-decoration: underline; }
code, pre { font-family: "SF Mono", "Fira Code", monospace; font-size: 0.9em; }
/* 文字 */
.text-center { text-align: center; }
.text-left { text-align: left; }
.text-right { text-align: right; }
.fw-bold { font-weight: 700; }
.fs-sm { font-size: 0.875rem; }
.fs-lg { font-size: 1.25rem; }
/* 間距系統 (4px 基準) */
.m-0 { margin: 0; } .mt-1 { margin-top: 4px; } .mb-2 { margin-bottom: 8px; }
.p-0 { padding: 0; } .px-3 { padding-left: 12px; padding-right: 12px; }
/* 佈局 */
.d-flex { display: flex; }
.flex-1 { flex: 1; }
.justify-between { justify-content: space-between; }
.align-center { align-items: center; }
.grid { display: grid; }
.gap-4 { gap: 16px; }
/* 顯示/隱藏 */
.d-none { display: none; }
.sr-only {
position: absolute; width: 1px; height: 1px;
padding: 0; margin: -1px; overflow: hidden;
clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}
/* 清除浮動 */
.clearfix::after { content: ""; display: table; clear: both; }
/* styles.css */
@import "base/reset.css"; /* Normalize/Reset */
@import "base/variables.css"; /* CSS 變數:色彩、間距、斷點 */
@import "base/typography.css"; /* 字體系統 */
@import "layout/grid.css"; /* 佈局系統 */
@import "components/"; /* 元件樣式 */
@import "utilities.css"; /* 工具類別(最後載入,最高優先權) */