homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / CSS
Forum Library, Charter, Moderators: not2easy

CSS Forum

Content Structure in the CSS document

 3:40 pm on Nov 4, 2002 (gmt 0)

Are there any recommended structures for CSS documents themselves?

In my own CSS documents, I begin with body, but then do the classes/ids that involve page-layout, then move into font formatting and finish with link formatting.

It ends up something like this:


p h1 li etc{

#contextual fontstuff{

#contextual a{

and so on.

I suppose some have the contextual elements adjacent to the parents instead of categorizing by what the id/class does.

How do you structure your CSS?



 3:55 pm on Nov 4, 2002 (gmt 0)

I've found that keeping the font stuff and the layout stuff in two different stylesheets is easier. Then just link to both of them. This is just down to personal preference though (and working on big sites, where keeping it all in one is not sensible at all).


 4:07 pm on Nov 4, 2002 (gmt 0)

I generally mirror the html flow. That way when I see something awry on my page, I know roughly where to find it.

As for general classes etc: At the bottom mainly ;)



 4:12 pm on Nov 4, 2002 (gmt 0)

I've been keeping mine in alphabetical order. Makes it easier to manage. I've done some research on this and cannot find anything that says the rules should be in a certain order.


 4:39 pm on Nov 4, 2002 (gmt 0)

I try to keep them in a completely random order, so that when I need to change a certain class the probability that I am already at the right point within the file is the same for all definitions contained within the file and all points within the file. ;)

The algo to maintain such a random order is pretty easy. Just put a new definition whereever you already are in that file.

I rely on good comments within my css files to find the ones I need. The comments are then stripped of by my cms on publishing the site.



 10:42 pm on Nov 4, 2002 (gmt 0)

How do you structure your CSS?

Like edit_g I split it up. I'll have one sheet dedicated to the actual layout/positioning. One sheet for the element styles and usaully one for navigation. If there are separate dirs I might have a .css folder dedicated to that directory alone.

Within the .css files I tend to start with the body tag and work my way down through id's and <div>'s. Then more general rules and classes round out the bottom. But it's all subjective- no set way at all. Comment your .css until your blue in the face too...this will help sort it out.


 11:57 pm on Nov 4, 2002 (gmt 0)

Does everyone use this [jigsaw.w3.org...] to check the CSS for errors. It is amazing how much incomplete or incorrect CSS now inhabits the web.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / CSS
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved