統一瀏覽器預設差異。推薦:
html,body,div,h1-h6,ul,ol,li,p,blockquote,pre,form,fieldset,table,th,td{margin:0;padding:0;}禁用:*{margin:0;padding:0;} —— 破壞表單元素原生樣式(radio/checkbox/select),效能差。
統一團隊協作規範,快速定位屬性。
/* 推薦:字母序 */
div#header h1 {
border-bottom: 1px solid #dedede;
color: #000;
font-size: 18px;
line-height: 24px;
margin-right: 48px;
position: relative;
z-index: 101;
}
公司規範優先,個人偏好其次,但專案內必須一致。
/***** Reset *****/
/***** Basic Elements *****/ /* body, h1-h6, a, p, ul, ol... */
/***** Generic Classes *****/ /* .float-left, .clearfix, .hide... */
/***** Basic Layout *****/ /* #header, #footer, .container... */
/***** Header *****/
/***** Content *****/
/***** Footer *****/
/***** Etc *****/
同類群組、註解分隔、加入「註解標幟」(如 /* =Header */)方便編輯器跳轉。
#fff vs #ffffff)統一。div#header{float:left;width:100%;}<div>、id、class(divitis/classitis)。>、相鄰選擇器 +、屬性選擇器,減少類名依賴。font-family: \5b8b\4f53(宋體)、\5fae\8f6f\96c5\9ed1(微軟雅黑),避免編碼問題、縮短代碼。