Reset CSS 的目的,不是把所有樣式粗暴歸零,而是先降低瀏覽器預設差異,再依需求重設合理樣式。以下是一份兼顧中文環境與現代瀏覽器的 reset 範例。
/* 清除內外邊距 */
body, h1, h2, h3, h4, h5, h6, hr, p, blockquote,
dl, dt, dd, ul, ol, li, pre,
fieldset, legend, button, input, textarea, th, td {
margin: 0;
padding: 0;
}
/* 基本字體 */
body, button, input, select, textarea {
font: 12px/1 Tahoma, Helvetica, Arial, "\5b8b\4f53", sans-serif;
}
h1 { font-size: 18px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }
h4, h5, h6 { font-size: 100%; }
address, cite, dfn, em, var { font-style: normal; }
code, kbd, pre, samp, tt {
font-family: "Courier New", Courier, monospace;
}
small { font-size: 12px; }
ul, ol { list-style: none; }
a { text-decoration: none; }
a:hover { text-decoration: underline; }
abbr[title], acronym[title] {
border-bottom: 1px dotted;
cursor: help;
}
q:before, q:after { content: ''; }
legend { color: #000; }
fieldset, img { border: none; }
button, input, select, textarea {
font-size: 100%;
}
table {
border-collapse: collapse;
border-spacing: 0;
}
hr {
border: none;
height: 1px;
}
html {
overflow-y: scroll;
}
沒有任何 reset 能一網打盡所有專案。建議依網站屬性裁剪,例如電商、媒體、後台或個人網站,所需的預設樣式各不相同。上線前可使用壓縮版本,並搭配測試頁確認差異。
好的 reset 不是讓頁面變得空白,而是讓開發從一個可預測、可維護的起點開始。