2 replies [Last post]
Manzell
Offline
newbie
Seattle, WA
Last seen: 17 years 10 weeks ago
Seattle, WA
Joined: 2003-07-18
Posts: 6
Points: 0

Is there an 'established' order in which order classes/ids/etc should appear in your CSS document?

I've been considering organizing in alphabetical order by element selected (ie, #nav li.submenu would be listed under li) which would make it easiest for someone reviewing the CSS to look for that particular element... on the other hand, should #nav and everything underneath that (#nav a:hover...) be next to #nav, so that all nav selectors are close to each other...

is there a web standard?

- MRB

rmfred
rmfred's picture
Offline
Elder
Rock Springs, WY
Last seen: 1 year 50 weeks ago
Rock Springs, WY
Timezone: GMT-6
Joined: 2004-01-31
Posts: 1073
Points: 31

code formatting in CSS doc

Not an expert... but I don't believe there is a "standard"?
I've read varying ideas...
1. put all your normal html tags first... p, h1 h2 etc etc
2. group by categories... text, colors, backgrounds
3. group by selectors... #nav then everything that corresponds to #nav
and the list goes on and on...

personally I like to group as the page is layed out...for example

body
container
header
menus
content
footer

that works best for me...
I would say do whatever works for you... but comment the code in case someone else should have to follow your work

just my .02

obsidian
Offline
Enthusiast
South Carolina
Last seen: 13 years 48 weeks ago
South Carolina
Joined: 2004-08-15
Posts: 136
Points: 0

code formatting in CSS doc

I would agree with grouping everything according to how it is layed out on the page. As there is no "requirement" for how you lay things out, you need to keep in mind that if you change something too early in your CSS, it will be inherited by everything from that point on. I like to be very specific with my classes and id's, and I do like to try to keep all classes under the specific tag you are modifying, or you can come up with some rather interesting outcomes Wink

You can't win, you can't lose, you can't break even. You can't even get out of the game!