Home / CSS3 / HOW DO I ORGANISE MY CSS?
css3-media-queries

HOW DO I ORGANISE MY CSS?

You know mediaqueries are the cornerstone of responsive design, however just where and how you enable each media query depends on your implementation.

With responsive design still in its infancy there are many techniques that are being used to deliver the right CSS to the right breakpoint.

You could

  • Use Javascript to serve relevant CSS files
  • Use media=”” tag within the header
  • Use @media within the  file
  • Use a mixture of all the above.
  • An example of option 2

 




Have a look at these three slideshare presentations to start:

Beautiful Maintainable
Maintainable
Efficient, maintainable, modular
Firstly, and most importantly, document . Whatever method you use to organize , be consistent and document it. Describe at the top of each file what is in that file, perhaps providing a table of contents, perhaps referencing easy to search for unique tags so you jump to those sections easily in your editor.

If you want to split up into multiple files, by all means do so. Oli already mentioned that the extra HTTP requests can be expensive, but you can have the best of both worlds. Use a build script of some sort to publish your well-documented, modular  to a compressed, single file. The YUI Compressor can help with the compression.

In contrast with what others have said so far, I prefer to write each property on a separate line, and use indentation to group related rules. E.g. following Oli’s example:

#content {
/* CODE */
}
#content div {
/* CODE */
}
#content span {
/* CODE */
}
#content etc {
/* CODE */
}

#header {
/* CODE */
}
#header etc {
/* CODE */
}
That makes it easy to follow the file structure, especially with enough white space and clearly marked comments between groups, (though not as easy to skim through quickly) and easy to edit (since you don’t have to wade through single long lines  for each rule).

Understand and use the cascade and specificity (so sorting your selectors alphabetically is right out).

Whether I split up  into multiple files, and in what files depends on the size and complexity of the site . I always at least have a reset.css. That tends to be accompanied by layout.css for general page layout, nav.css if the site navigation menus get a little complicated and forms.css if I’ve got plenty  to style my forms. Other than that I’m still figuring it out myself too. I might have colors.css and type.css/fonts.css to split off the colors/graphics and typography, base.css to provide a complete base style for all HTML tags…

About Sushil_kumar

Check Also

css3-media-queries

Media Queries for iPads, iPhones ,iPhones5, iPhones6, Tabs, and all Mobile Phones

Many times I had to design responsive websites targeting specific devices with CSS media queries, …

Leave a Reply

Your email address will not be published. Required fields are marked *

0

February 23, 2017

Clear all

Warning: Cannot modify header information - headers already sent by (output started at /home/u797196687/public_html/wp-content/themes/sushil/framework/functions/common-scripts.php:611) in /home/u797196687/public_html/wp-content/plugins/wppush-push-notifications/WPPush.php on line 274