通過借鑑網上大牛們的經驗和自己在工作中碰到的一些問題,總結出了這些比較常用的CSS樣式重置的代碼:
@charset "utf-8"; /* 防止用戶自定義背景顏色對網頁的影響,添加讓用戶可以自定義字體 */ html{ color: #000; background: #fff; -webkit-text-size-adjust: 100%; -ms-text-size-adjust: 100%; font-size: 100%; } /* IE6對positon:fixed的單獨處理修正IE6滾動抖動的bug */ *html,*html body{ background-image:url(about:blank);/*修正IE6滾動抖動的bug*/ background-attachment: fixed;/*根據自己實際,非必需*/ } /* 內外邊距通常讓各個瀏覽器樣式的表現位置不同 */ body,div,dl,dt,dd,ul,li,pre,form,fieldset,select,input,textarea,button,p,blockquote,th,td,img,iframe{ margin: 0; padding: 0; } body{ width: 100%; } /* 要注意表單元素並不繼承父級 font 的問題 */ body,button,input,select,textarea{ font: 12px/1.5 "微軟雅黑","Microsoft YaHei","\5b8b\4f53","Tahoma","Arial"; color: #333; outline: none; } input,select,textarea{ font-size: 100%; } /* 重置button邊框 */ button{ border: none; } /* 去掉各Table cell 的邊距並讓其邊重合 */ table{ border-collapse: collapse; border-spacing: 0; } /* IE bug fixed: th 不繼承 text-align*/ th{ text-align: inherit; } /* 對齊是排版最重要的因素, 別讓什麼都居中 */ caption,th{ text-align: left; } /* 去除默認邊框 */ fieldset,img{ border: none; outline: none; -moz-outline:none; } /* ie6 7 8(q) bug 顯示爲行內表現 */ iframe{ display: block; } /* 去掉列表前的標識, li 會繼承 */ ol,ul,li{ list-style: none; } /* 來自yahoo, 讓標題都自定義, 適應多個系統應用 */ h1,h2,h3,h4,h5,h6{ font-size: 100%; font-weight: 500; margin: 0; padding: 0; } /* 讓鏈接默認不顯示下劃線,在hover狀態下顯示下劃線 */ a{ color: #333; cursor: pointer; outline: none; text-decoration: none; blr:expression(this.onFocus=this.blur()); } a:hover{ text-decoration: underline; } /* 清理浮動 */ .clearfix:before,.clearfix:after{ display: block; content: " "; clear: both; } .clearfix{ zoom: 1; /* for ie67*/ } /* 重設 HTML5 標籤, IE 需要在 js 中 createElement(TAG) */ article,aside,details,figcaption,figure,footer,header,hgroup,menu,nav,section{ display: block; } /* HTML5 媒體文件跟 img 保持一致 */ audio,canvas,video{ display: inline-block; *display: inline; *zoom: 1; } address,caption,cite,code,dfn,em,th{ font-style: normal; font-weight: normal; } /*解決盒模型問題css3屬性也可用來統一FORM元素風格*/ .box-sizing{ -moz-box-sizing: border-box; -webkit-box-sizing: border-box; -o-box-sizing: border-box; -ms-box-sizing: border-box; box-sizing: border-box; }