News for hackers. Stuff that matters.
Re:Ask HN: Anyone have a really smart way to organize css? by zefhous on Monday March 28, 2011 @12:29AM (#2377155)
Ideally, I use Sass with Compass (http://compass-style.org/). This alone is a great start to keeping things organized. One of the things I love about Sass is that it allows partials and variable declarations, which both help immensely with code organization.

Then, my code is usually organized as follows. Each section can be extracted to a partial if it gets long enough or if more separation is desired.

  Framework includes and resets
  Variable declarations — colors, possibly specific widths  
  Universal method declarations
  Standard global tags — headings, p, a, ul, li, etc... 
  Generic form styling, usually in a dedicated partial
  Layout — container, header, content, footer
  Then to specific section styling
Since Sass uses indentation, I indent everything in each section within a top level tag. This really helps visually distinguish each section and gives a much less uniform look to the stylesheet which makes it a lot more scannable. If a section uses methods exclusively I'll declare them just above the top-level section tag.

I'm pretty happy with this approach. It was formed fairly organically but become more defined as I use it for more projects. It also seems to work well for both large and small projects, since partials can be used when the code starts getting long.

Re:Ask HN: Anyone have a really smart way to organize css? by nagash on Monday March 28, 2011 @12:41AM (#2377179)
The biggest problem that I have with Sass is that the file/line references in your developer tools point at the compiled CSS files, and so you don't have any real reference to where in your Sass files that style is defined. Any solution for this?
Re:Ask HN: Anyone have a really smart way to organize css? by panpainter on Monday March 28, 2011 @01:19AM (#2377241)
There actually is; SASS has built-in functionality that will actually inject the source filename/line-number in to the generated CSS. Additionally, Nathan Weizenbaum (one of the HAML/SASS maintainers) released a Firefox/Firebug add-on that will read this and display it in Firebug like it does for traditional CSS.

More on debug-mode: http://sass-lang.com/docs/yardoc/file.SASS_REFERENCE.html#de...

Grab the Firefox add-on here: https://addons.mozilla.org/en-US/firefox/addon/firesass-for-...

Re:Ask HN: Anyone have a really smart way to organize css? by zefhous on Monday March 28, 2011 @01:20AM (#2377244)
Yes, Sass provides a setting that prints the source line numbers with the compiled CSS for development. I think this is on by default, but you can turn it on in the config file with:

  Sass::Plugin.options[:line_comments] = true
  # or with compass:
  sass_options = {:line_comments => true}
Sass compiles code like this:

  /* line 138, sass/screen.sass */
  #navigation a:hover {...}
I guess it can be a problem sometimes, but I don't usually have issues with it and find that the organizational benefits outweigh the drawbacks by a long shot.
Re:Ask HN: Anyone have a really smart way to organize css? by chadcf on Monday March 28, 2011 @01:21AM (#2377248)
If you are using Firefox/Firebug you can try this:

https://addons.mozilla.org/en-US/firefox/addon/firesass-for-...

Doesn't seem to support FF4 yet though.

Re:Ask HN: Anyone have a really smart way to organize css? by robflynn on Monday March 28, 2011 @01:20AM (#2377243)
For me, at least in my rails project using Sass (scss): Development mode also creates inline comments in the generated CSS which describe where, in the original scss, the information can be found.

What an awkward sentence. I need sleep.

Re:Ask HN: Anyone have a really smart way to organize css? by lynnwallenstein on Monday March 28, 2011 @03:28AM (#2377507)
Another option if you are using something like rails is in your development mode just link to the individual CSS files (http://forrst.com/posts/Rails3_Linking_to_CSS_Differently_De...)
Re:Ask HN: Anyone have a really smart way to organize css? by dogonwheels on Monday March 28, 2011 @01:21AM (#2377247)
I think the line_comments option might be some help.