欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

書寫CSS的5個小技巧讓你的樣式更規(guī)范

  發(fā)布時間:2013-08-13 11:47:36   作者:佚名   我要評論
CSS在書寫過程中會一些小技巧,會省時省力,比如按字母順序來排列css、先標記 后css等等,本文整理了一些,感興趣的朋友可以參考下希望對大家書寫css有所幫助
1. 按字母順序來排列css
不按字母順序排的:

復制代碼
代碼如下:

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;
}

理由是這樣的:可以更好的找到某個屬性。
2. 更好的組織css結(jié)構(gòu)
使用css注釋來給css分組,這樣結(jié)構(gòu)明了,也有利于協(xié)同設(shè)計。
/*****Reset*****/
xxxxxxx{www.sytm.net}
xxxxx{xxxxx}
/*****layouts*****/
xxxxxxx{www.sytm.net}
xxxxx{xxxxx}
3. 保持一致性
不要無意義的去討論到底一個選擇器的所有屬性寫在一行,還是每個屬性寫一行比較好。如果你就喜歡寫在一行,因為每排寫一行會讓整個文檔感覺太長了,找起來不方便。但是發(fā)給team的另一個人,他卻喜歡每句排一行,那怎么辦?其實很簡單,把css拿去w3c驗證,它會有一份結(jié)果,會自動轉(zhuǎn)換成每排一行。
4. 先標記 后css
對html的標記弄好后再寫css會比較不容易出錯。比如寫一個頁面,先寫一個最基本的標記結(jié)構(gòu)<body>

復制代碼
代碼如下:

<div id="wrapper">
<div id="header"><!--end #header-->
<div id="container">
<div id="content">
</div><!--end #content-->
<div id="sidebar">
</div><!--end #sidebarr-->
</div><!--end #container-->
<div id="footer">
</div>!<--end #footer-->
</div><!--end #wrapper-->
</body>

然后就是盡量善用子選擇器,而不是一要給哪個元素進行樣式化,就給它添加個選擇器。
5. CSS Reset/重置
你可以copy Eric Meyer Reset, YUI Reset或其它css reset, 但你接下來應該根據(jù)你的項目改成你自己的reset.
* { margin: 0; padding: 0; }這句并不適用一些元素比如單選按鈕,不過有單選按鈕就重新給單選按鈕重設(shè)就好了嘛。

相關(guān)文章

最新評論