標籤:
1. CSS瀏覽器支援標準
|
WinXP |
Win7 |
OS X |
| IE9 |
C |
C |
|
| IE8 |
A |
A |
|
| IE7 |
A |
A |
|
| IE6 |
A |
A |
|
| Chrome7 |
C |
C |
C |
| Chrome6 |
A |
A |
A |
| Chrome3 |
B |
B |
B |
| Firefox4 |
C |
C |
C |
| Firefox3.6 |
A |
A |
A |
| Firefox3.5 |
C |
C |
|
| Firefox3 |
C |
C |
|
| Safari |
B |
B |
B |
| Opera |
C |
C |
C |
(註:根據2010年11月10日資料整理)
-
A級-互動和視覺完全符全設計的要求
-
B級-視覺上允許有所差異,不破壞頁面整體效果
-
C級-可忽視視覺上的問題,但不防礙使用
2. 儘可能的通過繼承和層疊重用已有樣式3. 根據建立樣式的適用範圍分為三級:全站級、產品級、頁面級
頁面級指僅在一個或少量幾個頁面中用到。如果僅在一個頁面中用到的採用內聯方式嵌入於頁面head裡,多於兩個頁面的放到外聯的CSS檔案中,該檔案再放到相應的產品目錄下。
4. core.css是全站基本樣式。它需要放在所有CSS引用的最前面。它包括:標籤reset、常用規則(連結、字型、隱藏、清浮動等)、布局、各種模組基本樣式等
參見:http://img3.douban.com/css/packed_core1.css
5. 不要輕易改動全站級CSS。改動後,要經過全面測試6. 單條CSS規則的書寫格式要求
.selector { property:value;property:value; }
.selector1,
.selector2,
.selector3 { property:value;property:value; }
-webkit-border-radius:4px;-moz-border-radius:4px;border-radius: 4px;
7. 將作用於不同模組的CSS規則集中放在一起,同時用注釋說明
注釋的格式:
/* mod: doulist */
通用規則同樣分類放在一起。通用規則在具體模組規則的前面。如:
/* button */
…
/* mod */
…
/* nav */
…
/* mod: events album */
8. ID和Class命名。命名不要用縮寫,單詞間用”-”做為串連符
壞:
#rec
.gray-link
.broadsmr
.pl
好:
#db-nav-main
.infobox
.item
-
8-4. 推薦使用的class名:
| 表示狀態 |
.on, .active, .selected, .hili |
| 表示位置 |
.first, .last, .main, .side |
| 表示結構 |
.hd, .bd, .ft, .col, .section |
| 通用元素 |
.tb, .frm, .nav, .list, .item, .tag, .pic, .info |
9. 盡量避免使用CSS Hack
推薦使用下面的:
區別屬性:
| IE6 |
_property:value |
| IE6/7 |
*property:value |
| IE6/7/8/9 |
property:value9 |
| 非IE6 |
property//:value |
區別規則:
| IE6 |
* html selector { … } |
| IE7 |
*:first-child+html selector { … } |
| 非IE6 |
html>body selector { … } |
| firefox only |
@-moz-document url-prefix() { … } |
| saf3+/chrome1+ |
@media all and (-webkit-min-device-pixel-ratio:0) { … } |
| opera only |
@media all and (-webkit-min-device-pixel-ratio:10000),not all and (-webkit-min-device-pixel-ratio:0) { … } |
| iPhone/mobile webkit |
@media screen and (max-device-width: 480px) { … } |
10. 使用after或overflow的方式清浮動11. 內聯和外聯的CSS都必須放在頁面的head裡。順序是:全站級CSS,產品級CSS,頁面級(外聯)CSS,頁面級(內聯)CSS,內聯CSS12. 避免使用低效的選取器
如:
body > * {…}
ul > li > a {…}
#footer > h3 {…}
ul#top_blue_nav {…}
#searbar span.submit a { … }
13. 盡量避免使用filter14. 不要直接修改標籤的樣式
如: div { … }
15. 不要在標籤上直接寫樣式
如:<div style=”margin-bottom:30px;”>
16. 不要在CSS中使用 expression17. 不要在CSS中使用 @import 18. 不要在CSS中使用 !important19. 絕對不要在CSS中使用 “*” 選擇符
豆瓣網前端開發規範之-css開發規範