CSS Organization Tip 1: Flags

In CSS Organization Tip 1: Flags, Doug Bowman explains the technique he uses to make navigating between different sections of CSS files easier.

This is something I need to get better at. I start out each project keeping things organised, but never seem to be able to keep it up until the end. Good. More things for my to-do list.

  • May 3, 2005
  • Comments closed
  • Posted in

Comments

1. May 4, 2005 by Woolly Mittens

Do you know what also makes a world of difference? Using tabs to shift the children further than the parents.

parent {}

#child {} __#child h1 {} _#child p {}

(_'s added for display here only)

That way you can spot the root elements at a glance.

2. May 4, 2005 by Woolly Mittens

grrr... it's very hard to illustrate things with ascii here.

parent {}

---#child {}

------#child h1 {}

------#child p {}

(---'s added for display here only)

3. May 4, 2005 by Tommy

I usually structure my CSS files like this:

  1. Generic element styles (alphabetic element name order).

  2. Styles for specific IDs (with child elements indented as Woolly Mittens described). The IDs are in the order they occur in the documents.

  3. Styles for classes (alphabetic class name order).

  4. Rules for combinations of selectors (e.g. h2+p).

Sometimes I have structured the rules according to their use (e.g. positioning, typography). Depending on the style sheet, this can sometimes reduce the size by half.

4. May 4, 2005 by Jens Meiert

You could use selectors to sort your style sheets (as I prefer, indicated in my original article comment), as you could also create specific functional sections. One should specify guidelines for this (...thinking about publishing some guidelines I once wrote, too, since it might be an alternative advancement).

5. May 4, 2005 by Lud

I'm still waiting for a css editor that is able to show the depencies between several elements.

6. May 4, 2005 by Milan Negovan

In Visual Studio.NET (much like in almost any code editor) and can set apart a code region (#region ... #endregion) which you can expand and collapse. Helps a ton with large source code files.

I wish CSS editors had this kind of convention so you could jump from over region to another in a way Doug described.

7. May 6, 2005 by Roger Johansson

Woolly: Sorry about that. Check the Markdown syntax to understand what happened ;-).

Milan: There are text editors that will let you do that. I remember coming across that feature some time ago when I was trying out a bunch of editors, but I can't remember which one it was. It's a nice feature.

Sorry, comments are closed for this post.

Information, sponsorship, and externals

About the author

Roger Johansson is a Swedish web professional specialising in web standards, accessibility, and usability. More about me and this site.

Subscribe

Looking for web hosting?

Try DreamHost!

Use the promo code 456BEREASTREET3 to save USD 20 when you sign up!

Latest articles

Validation statistics from Nikita the Spider Comments off
An analysis of the sites crawled by the bulk validation tool Nikita the Spider during March 2008.
Authentic Jobs API and Affiliates program Comments off
The Authentic Jobs job listing service now has a public API and an affiliate program.
What does Acid3 mean to you and me? Comments off
Opera and Apple have announced that their web browsers pass the Acid3 Browser Test, but how will that help web designers and developers?
Designing Web Navigation (Book review) Comments off
Learn the fundamentals of navigation design and design better navigation systems for large and small sites as well as for web based applications.
DOMAssistant bundle for TextMate Comments off
To save keystrokes and speed up development I have created a DOMAssistant bundle for TextMate.
First impressions of Internet Explorer 8 Beta 1 Comments off
My impressions after trying out Internet Explorer 8 Beta 1 for a couple of days.

More articles

Favourites, here and elsewhere

Affiliation

  • NetRelations
  • Kaffesnobben
  • Dagens recept
  • 9rules network member

Support this site

Show your support by buying a book or two from SitePoint or getting me something from my Amazon Wish List.