在實際動手寫 CSS 之前,先做一份稱手的 reset 往往是好習慣,它能抹平不同瀏覽器之間的預設樣式差異,讓後續的樣式更好控制。以下是一份融合 Eric Meyer 與 YUI 思路的重置程式碼:
/* 統一邊距與內距 */
body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,form,fieldset,input,p,blockquote,th,td { margin:0; padding:0 }
/* 統一標題字號 */
h1,h2,h3,h4,h5,h6 { font-size:100% }
/* 移除清單樣式 */
ol,ul { list-style:none }
/* 統一字號與字重為正常 */
address,caption,cite,code,dfn,em,strong,th,var { font-size:normal; font-weight:normal }
/* 收合表格邊框 */
table { border-collapse:collapse; border-spacing:0 }
/* 移除 fieldset 與圖片邊框 */
fieldset,img { border:0 }
/* 讓 caption 與 th 靠左對齊 */
caption,th { text-align:left }
/* 移除 q 的引號 */
q:before,q:after { content:'' }那麼實際寫專案時該怎麼做 reset 呢?個人推薦直接採用 Eric Meyer 與 YUI 這套成熟方案——它涵蓋了常見元素的邊距、字號、清單、表格與圖片邊框等重點,簡潔又通用,能幫你省下不少處理兼容性的力氣。