Dezinerfolio

CSS with a better approach

Your rating: None Average: 4.7 (23 votes)

CSS has been part of the web design backbone since ages until now and still getting better. When we spend huge amount of time developing, why not pay some attention on keeping things organized? Here we will try to develop CSS with a better approach.

Why this kind of approach?

  • Standards
  • Clean
  • Fast Access
  • lots...

.

Code Definition

A small section at the start of your CSS file where you define few details like Author, Version, Description.... Here is how it could look like:

 

/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

* Filename: grid.css

* Version: 1.0.0 (2007-09-21) YYYY-MM-DD

* Website: http://site.com/

* Author: Name

* Description: Handles the site layout.

== STRUCTURE: ==============================

* Page width: 950 px

* Number of columns: 3

============================================ */

 

Version based

Building versions of your CSS file helps you refer to your previous code or even restore an old one if required by any chance. So, keeping this snippet in the above code definition is a better practice.

* Version: 1.0.0 (2007-09-21) YYYY-MM-DD

Comments

Well, this is not for others but for you. If you need to have a better understanding on whatever you have coded and not get confused when you look at few thousand lines of CSS, go with this...

Anchors

As I said above... if you are kind of person working on CSS files of a few thousand lines, this will be your best friend from now on. This is something similar to the HTML anchoring within the same page. The basic idea in CSS is that you will be adding commented sections with a unique character prefix for a quick search. You will have these unique named sections defined under your code definition so that you even get an overview of all the sections defined in that particular CSS file. Here is how it goes in the CSS file: Your Code Definition (header of the CSS file)

== INDEX: ===================================

_header : Site Heading

_rightnavi : Right Navigation

_accordion : Accordion Menu

============================================

Following CSS definitions You will be defining such anchors at the start of every section and also define the same in the code definition as above. When you need to get to a particular section, you will simply search for one of the anchors from the above index and your editor will take you straight to the section.

/* _header <the anchor>

==========================================*/

#header{ <attributes> }

#header .logo{ <attributes> }

. . . <long long list of your CSS definitions>

/*

_accordion

==========================================*/

. .

<long long list of your CSS definitions>

Framework style

We now have a lot of CSS frameworks too popping out. CSS frameworks have both advantages and disadvantages. Read SmashingMagazine's article on CSS frameworks. For now, we will follow some advantages of CSS frameworks within our code. Your CSS can be broken down into different files like:

  • typography.css for basic typographic rules,
  • grid.css for grid-based layouts or
  • layout.css for general layouts,
  • form.css for basic form styling,
  • general.css for further general rules

This way, you will have shorter code in each file which is more accessible. You will only have a base CSS file which will be included in your HTML and the above abstracted CSS files will be imported within your base CSS file using the @import url("filename.css");

.

Well... this is what we have been following in our projects and really feel much better with these standards. Hope this article has been informative to you. If you have any more ideas on this approach, please share below.

Trackback URL for this post:

http://www.dezinerfolio.com/trackback/145

Comments

Anonymous's picture

Hallo
In my gallery instalasion i see this problem
Required Extensions
curl is loaded. json is disabled.Please load the required PHP extensions in your php.ini before you continue.

Anonymou-sseitaridis (not verified)
Sat, 10/17/2009 - 13:15
Anonymous's picture

my personal favorite of all the posts in df! :)

aravind (not verified)
Tue, 02/17/2009 - 07:40
Anonymous's picture

Hello some interesting information. I add to my favorite.

Pitter (not verified)
Sat, 08/30/2008 - 16:12
Anonymous's picture

CSS "Cascading Style Sheets" Lessons
css list style Properties and examples -- http://css-lessons.ucoz.com/list-css-examples.htm

css map (not verified)
Tue, 08/12/2008 - 06:43
Anonymous's picture

Spasibo!!!!!

bocman1 (not verified)
Thu, 06/12/2008 - 09:48
Anonymous's picture

Why not using a backend code to compile all the CSS' file contents into one CSS stream and send it to the requesting browser....

this will minimize HTTP requests and deziners will also attain simplicity.

in my current project where i am building a framework for all future website developments for a fortune 500 giant, i am just calling a backend function that writes in everything including the JS, Moo Framework, CSS, etc making the number of HTTP requests minimized to the max

kishu (not verified)
Mon, 06/02/2008 - 04:36
Anonymous's picture

Yes you should keep your CSS in one file to minimize the number of HTTP requests to speed up the page display. You could aggregate them later in one file using dynamic code in your section.

Julien (not verified)
Wed, 04/09/2008 - 00:40
Anonymous's picture

Multiple css files mean multiple http request which results in longer loading times. importing all the files in the standard css file makes no difference

David (not verified)
Tue, 03/04/2008 - 05:46
Anonymous's picture

I've started using the header information for my FLAs. Its just as helpful, digging into someone else's FLAs can be a nightmare. I changed website to "live URL", so if someone pops open a fla, they can see which page it's been embedded on.

Bonnie (not verified)
Mon, 02/11/2008 - 08:17
dfadmin's picture

@veerendra - its not "calling four cs sheets for different elements". We are just breaking the main file into different files for better understanding.

All these files are included inside your base CSS file + your base CSS file will be included in your HTML.

Indirectly all the CSS files are included but are somewhat hidden...

Tue, 01/29/2008 - 15:57

Post new comment

The content of this field is kept private and will not be shown publicly.

Visualize