Live data from Hacker News

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

news.ycombinator.com

121–122 of 122 posts

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

#121

On an MVC site, I organize by controller. There's one general file for generic cross-site stuff (header/footer, etc.), supplemented by another CSS file that shares the markup for all controller-specific pages. This gives a max of two css files per page. For the landing page I compress the generic file along with the controller-specific css file for the default page into a single file. This speeds up the loading proce…

I also organize styles by controller/action in my Rails projects. This trick from "The Rails 3 Way" is great for assigning the correct classes to the page:

Using Haml:

  %body(class="#{controller.controller_name} #{controller.action_name}")
Using Erb:

  '>

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

#122
I typically generate css with php, usually in the header but sometimes in a linked file. Using this method I can easily alter site wide color or fonts, etc or feed the style atrributes from a database. This method also allows me to create blocks of css for different page elements and include them as needed - forms, menus, etc - or dynamically include definitions when conditions are met. This offers a lot of flexibility in terms of organizing and making changes to the css.
Post reply on HN