並非所有 CSS Reset 都追求「全部歸零」。Rudeworks 這套走的是實用路線——只重設真正造成困擾的部分,其餘保留瀏覽器該有的合理預設。
* {
margin: 0;
padding: 0;
border: none;
}
html {
font: 62.5% "Lucida Grande", Lucida, Verdana, sans-serif;
text-shadow: #000 0px 0px 0px;
}
ul {
list-style: none;
list-style-type: none;
}
h1, h2, h3, h4, h5, h6, p, pre,
blockquote, ul, ol, dl, address {
font-weight: normal;
margin: 0 0 1em 0;
}
cite, em, dfn { font-style: italic; }
sup {
position: relative;
bottom: 0.3em;
vertical-align: baseline;
}
sub {
position: relative;
bottom: -0.2em;
vertical-align: baseline;
}
li, dd, blockquote { margin-left: 1em; }
code, kbd, samp, pre, tt, var,
input[type='text'], textarea {
font-size: 100%;
font-family: monaco, "Lucida Console", courier, mono-space;
}
del { text-decoration: line-through; }
ins, dfn { border-bottom: 1px solid #ccc; }
small, sup, sub { font-size: 85%; }
abbr, acronym {
text-transform: uppercase;
font-size: 85%;
letter-spacing: .1em;
border-bottom-style: dotted;
border-bottom-width: 1px;
}
a abbr, a acronym { border: none; }
sup { vertical-align: super; }
sub { vertical-align: sub; }
h1 { font-size: 2em; }
h2 { font-size: 1.8em; }
h3 { font-size: 1.6em; }
h4 { font-size: 1.4em; }
h5 { font-size: 1.2em; }
h6 { font-size: 1em; }
a, a:link, a:visited, a:hover, a:active {
outline: 0;
text-decoration: none;
}
a img { border: none; text-decoration: none; }
img { border: none; text-decoration: none; }
label, button { cursor: pointer; }
input:focus, select:focus, textarea:focus {
background-color: #FFF;
}
fieldset { border: none; }
.clear { clear: both; }
.float-left { float: left; }
.float-right{ float: right; }
body { text-align: center; }
#wrapper {
margin: 0 auto;
text-align: left;
}
font: 62.5% 的設計。把 html 字級設成 62.5%,等於 10px(16 × 0.625)。這樣後續寫 font-size: 1.2em 就是 12px、1.4em 就是 14px,em 的數字與 px 幾乎一一對應,省去心算。缺點是使用者若調大字級,比例會一起縮水,對視力不佳者不友善——現代的 rem 加根字級方案更恰當。
sup 與 sub 用 position 微調而非 vertical-align。因為 vertical-align 對上下標的處理在各瀏覽器間差異很大,改用 position 加 bottom 偏移能獲得一致結果,同時再補一行 vertical-align: baseline 抵消瀏覽器預設值。
body 置中加 #wrapper 還原的經典手法。body{text-align:center} 配合 #wrapper{margin:0 auto;text-align:left},是 IE6 時代做「整體置中但內部文字左對齊」的標準寫法。今天直接用 margin: 0 auto 加上 max-width 即可,不需要 text-align 繞路。
text-shadow: #000 0px 0px 0px; 這行原意是「清除文字陰影」,但它實際上會產生一個完全重疊的黑色陰影,在某些渲染下會讓文字變粗。這是一個有爭議的寫法,建議直接移除。
a{text-decoration:none} 全域移除連結底線是無障礙上的大忌——使用者會失去辨識連結的能力。若一定要移除,至少要在 hover 與 focus 狀態補回視覺回饋。
另外,font-family: monaco, "Lucida Console", courier, mono-space 最後一項 mono-space 並非合法的字型名稱,應該是 monospace(通用字型族關鍵字),這是原文的一個筆誤。