參考 Eric Meyer Reset、YUI Reset,再依專案裁剪。避免 * { margin:0; padding:0; } —— 會破壞單選/複選框等表單元素預設外觀。若專案無表單可用,否則針對性重置:
body, div, p, h1-h6, ul, ol, li, table, th, td, form, input, textarea {
margin: 0; padding: 0;
}
ul, ol { list-style: none; }
img { border: 0; }
/* 無序,難查找 */
div#header h1 {
z-index: 101; color: #000; position: relative;
line-height: 24px; margin-right: 48px;
border-bottom: 1px solid #dedede; font-size: 18px;
}
/* 有序,秒級定位 */
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 *****/
...
/***** Layout *****/
...
/***** Module *****/
...
/***** Theme *****/
團隊協作時可快速定位、減少合併衝突。
單行緊湊利於掃視整體;多行利於版本控制 diff。團隊協商後,發布前用工具(如 CSS Beautifier、W3C Validator 輸出)統一格式。
先完成語意化 HTML:
<body>
<div id="wrapper">
<header id="header"></header>
<div id="container">
<main id="content"></main>
<aside id="sidebar"></aside>
</div>
<footer id="footer"></footer>
</div>
</body>
再針對結構撰寫選取器,善用後代選取器(#content h2)避免到處加 class。