我一直在尋找組織CSS代碼的最佳方式,尤其是在大型網站上。我對寫作風格不感興趣,更關注人們如何構建和管理他們的代碼。CSS組織結構
我一直在關注這個結構,我覺得自己的作品相當不錯的可維護性,但我希望得到您對此的意見,並聽取其他方法:
/*=======================================
1. =reset
=======================================*/
/**
Anything but * reset
**/
/*=======================================
2. =base
=======================================*/
/**
Base rules so naked HTML has basic style and displays consistently x-browser
**/
/*=======================================
3. =base forms
=======================================*/
/**
Base form framework
**/
/*=======================================
4. =base site
=======================================*/
/**
Rules common across the majority of pages
e.g. header, footer, main columns, navigation, search bar etc.
**/
/*=======================================
5. =recurring styles
=======================================*/
/**
Re-useable snippets -- not to include positioning/structure etc.
e.g. buttons, icons etc.
**/
/*=======================================
6. =recurring modules
=======================================*/
/**
Re-usable modules common to multiple pages/views but not majority
e.g. a product carousel could be on the homepage as well as the product page and maybe even the checkout page etc.
**/
/*=======================================
7. =homepage
=======================================*/
/**
contains rules only applicable to homepage
**/
/*=======================================
8. =about page
=======================================*/
/**
contains rules only applicable to about page
**/
/*=======================================
9. =contact page
=======================================*/
/**
contains rules only applicable to contact page
**/
...and so on
任何想法,將不勝感激。
豐富
只是一個快速評論,但你使用任何形式的結構,在你的CSS事實上已經把你的頭和肩膀上面最。 :) 雖然我發現將單片樣式表分成多個文件使得讀取/調試/重用(雖然很明顯)變得更加容易,但我沒有看到您如何佈置它的任何錯誤。 – Faisal 2010-07-14 23:31:13
感謝您對此的反饋和想法,很高興聽到人們使用類似的結構,我也應該提到,這個例子並不一定意味着所有的規則應該在一個字段中,而只是一個部分的CSS規則的一種方式。 – Richard 2010-07-15 22:11:14