base.css(或稱 reset.css、normalize.css)是項目樣式系統的基石,核心目標:
/* ===== 1. 現代化 Reset ===== */
/* 參考 Normalize.css + 現代項目實踐 */
*, *::before, *::after {
box-sizing: border-box; /* 統一盒模型,避免 padding 撐大 */
}
html {
line-height: 1.5; /* 統一行高基準 */
-webkit-text-size-adjust: 100%; /* 防止 iOS 橫屏字體放大 */
-moz-tab-size: 4; tab-size: 4; /* 統一 Tab 寬度 */
}
body {
margin: 0; /* 移除默認 margin */
font-family: system-ui, -apple-system, BlinkMacSystemFont,
'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
color: #1a1a1a;
background: #fff;
}
/* 移除列表默認樣式 */
ol, ul, menu { list-style: none; margin: 0; padding: 0; }
/* 表格邊框合併 */
table { border-collapse: collapse; border-spacing: 0; }
/* 圖片/媒體預設響應式 */
img, video, canvas, svg {
display: block;
max-width: 100%;
height: auto;
vertical-align: middle;
}
/* 表單元素字體繼承 */
input, button, textarea, select {
font: inherit;
color: inherit;
}
/* 移除按鈕默認樣式 */
button, [type="button"], [type="reset"], [type="submit"] {
background: none;
border: none;
cursor: pointer;
}
/* 連結無文字裝飾 */
a { text-decoration: none; color: inherit; }
a:hover { text-decoration: underline; }
/* 語義化標籤顯式 display:block(舊瀏覽器) */
article, aside, footer, header, nav, section, main, figure, figcaption {
display: block;
}
/* 字號階梯 */
.fs-xs { font-size: 0.75rem; } /* 12px */
.fs-sm { font-size: 0.875rem; } /* 14px */
.fs-base { font-size: 1rem; } /* 16px */
.fs-lg { font-size: 1.125rem; } /* 18px */
.fs-xl { font-size: 1.25rem; } /* 20px */
.fs-2xl { font-size: 1.5rem; } /* 24px */
.fs-3xl { font-size: 1.875rem; } /* 30px */
.fs-4xl { font-size: 2.25rem; } /* 36px */
.fw-normal { font-weight: 400; }
.fw-medium { font-weight: 500; }
.fw-semibold { font-weight: 600; }
.fw-bold { font-weight: 700; }
.text-left { text-align: left; }
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-justify { text-align: justify; }
.truncate { /* 單行省略號 */
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.line-clamp-2 { /* 多行省略號 */
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
overflow: hidden;
}
.line-clamp-3 { -webkit-line-clamp: 3; }
/* Margin - 外距 */
.m-0 { margin: 0; }
.m-auto { margin: auto; }
.mx-auto { margin-left: auto; margin-right: auto; }
.my-auto { margin-top: auto; margin-bottom: auto; }
.mt-1 { margin-top: 0.25rem; } /* 4px */
.mt-2 { margin-top: 0.5rem; } /* 8px */
.mt-3 { margin-top: 0.75rem; } /* 12px */
.mt-4 { margin-top: 1rem; } /* 16px */
.mt-6 { margin-top: 1.5rem; } /* 24px */
.mt-8 { margin-top: 2rem; } /* 32px */
.mt-12 { margin-top: 3rem; } /* 48px */
/* mb, ml, mr, mx, my 同理 */
/* Padding - 內距 */
.p-0 { padding: 0; }
.p-1 { padding: 0.25rem; }
.p-2 { padding: 0.5rem; }
.p-3 { padding: 0.75rem; }
.p-4 { padding: 1rem; }
.p-6 { padding: 1.5rem; }
.p-8 { padding: 2rem; }
/* pt, pb, pl, pr, px, py 同理 */
/* Flex 佈局 */
.flex { display: flex; }
.inline-flex { display: inline-flex; }
.flex-1 { flex: 1 1 0%; }
.flex-auto { flex: 1 1 auto; }
.flex-initial { flex: 0 1 auto; }
.flex-none { flex: none; }
.flex-col { flex-direction: column; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.items-start { align-items: flex-start; }
.items-end { align-items: flex-end; }
.justify-center { justify-content: center; }
.justify-between { justify-content: space-between; }
.justify-around { justify-content: space-around; }
.gap-1 { gap: 0.25rem; }
.gap-2 { gap: 0.5rem; }
.gap-3 { gap: 0.75rem; }
.gap-4 { gap: 1rem; }
/* Grid 佈局 */
.grid { display: grid; }
.grid-cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid-cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid-cols-4 { grid-template-columns: repeat(4, 1fr); }
/* 定位 */
.relative { position: relative; }
.absolute { position: absolute; }
.fixed { position: fixed; }
.sticky { position: sticky; }
.inset-0 { top: 0; right: 0; bottom: 0; left: 0; }
.z-10 { z-index: 10; }
.z-50 { z-index: 50; }
/* 浮動清除 */
.clearfix::after {
content: "";
display: table;
clear: both;
}
.float-left { float: left; }
.float-right { float: right; }
/* 寬高 */
.w-full { width: 100%; }
.w-screen { width: 100vw; }
.h-full { height: 100%; }
.h-screen { height: 100vh; }
.min-h-screen { min-height: 100vh; }
.max-w-md { max-width: 28rem; } /* 448px */
.max-w-lg { max-width: 32rem; } /* 512px */
.max-w-xl { max-width: 36rem; } /* 576px */
.max-w-2xl { max-width: 42rem; } /* 672px */
/* 邊框 */
.border { border: 1px solid #e5e7eb; }
.border-0 { border: 0; }
.border-t { border-top: 1px solid #e5e7eb; }
.border-b { border-bottom: 1px solid #e5e7eb; }
.rounded { border-radius: 0.25rem; }
.rounded-md { border-radius: 0.375rem; }
.rounded-lg { border-radius: 0.5rem; }
.rounded-full { border-radius: 9999px; }
/* 陰影 */
.shadow { box-shadow: 0 1px 3px rgba(0,0,0,0.1); }
.shadow-md { box-shadow: 0 4px 6px rgba(0,0,0,0.1); }
.shadow-lg { box-shadow: 0 10px 15px rgba(0,0,0,0.1); }
.shadow-none { box-shadow: none; }
.block { display: block; }
.inline-block { display: inline-block; }
.inline { display: inline; }
.hidden { display: none; }
.invisible { visibility: hidden; }
.overflow-hidden { overflow: hidden; }
.overflow-auto { overflow: auto; }
.overflow-scroll { overflow: scroll; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
normalize.css → base.css → components.css → pages.css.btn-primary),工具類輔助微調