butlins
08-18-2008, 10:45 AM
I was wondering if anyone would be willing to share their best practice in how they structure their CSS files. I've attached a set of files I use when I'm starting a new site, so I don't get halfway through and discover I've forgot to put an include for Google Analytics.
Basically with my CSS files, I start with by importing a reset.css file which removes default HTML styling, so I'm starting with a clean slate. I've then got three files named after the media they're aimed at: screen.css, handheld.css and print.css. Finally I've got a set of files targeted at versions of IE with conditional comments (ie.css, ie7.css, ie6.css, ie55.css) and a CSS file with the rules surrounded by Tantek Celik's IE Mac band pass filter (iemac.css - which I don't really ever use so will probably drop soon).
The screen.css file starts with what I think of as 'Universal' HTML - elements that aren't associated with a class or ID. Then I've got my 'Universal' classes - for class rules that might pop up anywhere on a page. Next I've for class-based divs and any descendant selectors - div.infobox and div.infobox p, div.infobox h3, for example.
Finally I've got IDs and their descendant selectors, usually in the order that the IDs are used on the page.
It works for most situations, but locating and bug-fixing large files can get tiresome, so I'm wondering if what I'm doing is the most efficient way of structuring my rules, and whether other people have their own way of approaching this that I haven't thought of.
I know that some separate out the page layout from styling - I've not tried that as I'm not sure that shuttling between two files would make things easier, but I'm open to suggestions.
Basically with my CSS files, I start with by importing a reset.css file which removes default HTML styling, so I'm starting with a clean slate. I've then got three files named after the media they're aimed at: screen.css, handheld.css and print.css. Finally I've got a set of files targeted at versions of IE with conditional comments (ie.css, ie7.css, ie6.css, ie55.css) and a CSS file with the rules surrounded by Tantek Celik's IE Mac band pass filter (iemac.css - which I don't really ever use so will probably drop soon).
The screen.css file starts with what I think of as 'Universal' HTML - elements that aren't associated with a class or ID. Then I've got my 'Universal' classes - for class rules that might pop up anywhere on a page. Next I've for class-based divs and any descendant selectors - div.infobox and div.infobox p, div.infobox h3, for example.
Finally I've got IDs and their descendant selectors, usually in the order that the IDs are used on the page.
It works for most situations, but locating and bug-fixing large files can get tiresome, so I'm wondering if what I'm doing is the most efficient way of structuring my rules, and whether other people have their own way of approaching this that I haven't thought of.
I know that some separate out the page layout from styling - I've not tried that as I'm not sure that shuttling between two files would make things easier, but I'm open to suggestions.