Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you organise CSS in your project? [closed]

Tags:

css

stylesheet

One of the most challenging thing I have felt while working on (complex) web application is the organizing the CSS.Here are the different approaches we have tried on multiple projects.

1: Have a different stylesheet for every web page/module.

Obviously we were very new to web apps then, and this approach resulted in too many style sheets and too much repetition of styles. We had a tough time to achieve consistency across the application.

2: Have a common style sheets which is shared across the similar web pages.

This worked well for sometime until it became too complex. Also we found that we had too many exceptions which still resulted in tweaking common styles for particular cases, which if done incorrectly can affect different parts of the application and at some point it becomes difficult. Also having a large development team (across different time zones) and tough project timeline didn't helped our cause.

Although #2 works, but still we have seen our products still doesn't have the similar UI quality and consistency as we would like to.

Are there any CSS style guidelines that one should refer for very complex web 2.0 application. How do other people maintain their stylesheets?

like image 508
MOZILLA Avatar asked Jan 07 '09 17:01

MOZILLA


1 Answers

I've found myself in similar situations.

First off, make sure that you're using CSS effectively. If you don't feel like you're an absolute pro at using CSS, take some time to study up and you'll significantly reduce redundancy and end up with a stylesheet that's easier to work with.

In most cases, there isn't much of a performance hit if you consolidate all of your styles into one file, and in fact, splitting your styles into dozens of files just so that you can be sure to exclude any that won't be used is likely to result in longer loading times because of all of the extra requests. But as I'm sure you know, a massive CSS file can quickly grow into a headache to maintain.

Consider this hack to achieve a compromise. Use your language of choice (PHP for me) to serve up your CSS. By that I mean include your style file like this:

<link rel="stylesheet" type="text/css" href="styles.php" />

, have the header of that file return it with the text/CSS content type, and have that file

a) Pull multiple stylesheets into one file and/or b) Change how the styles are written depending on various parameters (file being loaded, user data, time of day, etc.)

A is a good solution overall for reducing developmental headache and page-loading overhead. B will likely necessitate you also setting appropriate file expiration dates to avoid having the browser just ignore whatever new styles you want to generate at the moment in favor of what was downloaded on the last visit. Since you can usually accomplish the same thing in B as you can by simply having a static stylesheet and dynamically-written element class/ID names, it's generally not an ideal solution unless if you're doing something really strange.

And get a designer to advise you on this kind of stuff. Often it's hard for us developers to wrap our heads around some of the finer points of efficient CSS as well as people trained in that specific area.

like image 141
Phantom Watson Avatar answered Oct 03 '22 05:10

Phantom Watson