Live data from Hacker News

Ask HN: Anyone have a really smart way to organize css?

news.ycombinator.com

41–50 of 122 posts

Re: Ask HN: Anyone have a really smart way to organize css?

#41
post #30

At some point, the amount of CSS complexity becomes best handled by a preprocessor. Stylus is great: http://learnboost.github.com/stylus/ I made a post about it, and personally prefer it to Sass and Less: http://nylira.com/stylus-the-revolutionary-successor-to-css/ The hardcore abbreviation mixins in my post seem to offend some coders. When you work in CSS and HTML hours every day though, every character saved adds u…

My current project has 30 directories with 73 partial Sass files, which compile down to one 320kb file. Isn't that a lot to download? That's like 2 seconds on average to download that file in the U.S., and probably in the 10 seconds or higher range for a lot of folks. I guess if the download is delayed to after some kind of engagement (sign up, etc) it's not a big deal? Is 320K of CSS really necessary? (legitimately…

IMHO, it's not.

I'm working on a few relatively complex web apps where the CSS download time don't come to anywhere near that size. In my world (mobile devices, in particular) 320k would be totally unacceptable. 100k is about the point where I start re-evaluating my design.

Re: Ask HN: Anyone have a really smart way to organize css?

#42
post #39

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 in…

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?

#43
I think alot of it depends what it is that you are building. My approach to would be different if it were building a large scale web app vs a website and it also depends on the team thats helping to maintain it (ie. if it were to be maintained by engineers who don't really know or care for css or a team of web devs)

I always start off with a base which consists of the misc. browser fixes and hacks + basic typography elements, rough blocking. My philosophy on formatting really follows what everyone here is saying. I really prefer horizontal lines and proper tabbing of all the sub elements because its really hard to read otherwise.

While commenting is really good and I like it, finding the proper balance is the key. When you're doing fast iteration it gets really tedious and cumbersome to go back and make sure your comments are in sync.

This is how i arrange my css: http://maderogue.com/public/assets/css/base.css

For bigger project I like to break things down by specific functions & models. (ie. tables, buttons, sorting controls, etc.)

i really like the way jquery ui themes are done.

Re: Ask HN: Anyone have a really smart way to organize css?

#44
Like many of the other commenters, I break the code into reset, global elements, layout, modules/blocks, and then special overrides if any.

I'll admit it's a personal preference, but as a team consideration I don't recommend the 'all properties on one line' approach. It's discouraged in other languages so why do it in CSS?

Definitely check out OOCSS as well as the Natalie Downe talk both posted by in the comments already.

I can't overstate how highly I recommend Sass/SCSS. It's been mentioned already as "for Ruby". Yes, you need Ruby installed to use Sass/SCSS but you do not need to be working on a Ruby project to use it. You can run "sass --watch (directory name)" from the command line and sass will automatically compile your .scss (or .sass) files to .css files upon save. Even if you're scared of the command line I assure you, it's easy! If you're a TextMate user, there's also a great SCSS bundle here: https://github.com/kuroir/SCSS.tmbundle (it was enough for me to abandon CSSEdit for good)

One thing that hasn't been discussed in this thread yet is the organization of properties within a declaration block. It's a good idea to have an approach and stick with it. Alphabetizing the properties is one approach. I wrote about my preferred approach a couple years ago here: http://fordinteractive.com/2009/02/order-of-the-day-css-prop... (also check out the SitePoint discussion linked in the "Further Reading" section of the post)

Re: Ask HN: Anyone have a really smart way to organize css?

#45
post #42
post #39

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 in…

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?

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?

#46
post #42
post #39

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 in…

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?

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?

#47
post #42
post #39

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 in…

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?

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?

#48
post #42
post #39

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 in…

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?

[deleted]

Re: Ask HN: Anyone have a really smart way to organize css?

#49
post #42
post #39

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 in…

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?

I think the line_comments option might be some help.

Re: Ask HN: Anyone have a really smart way to organize css?

#50
post #42
post #39

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 in…

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?

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.

Post reply on HN