» 5 Steps to Write Better CSS Part II
  • Home
  • About
  • Articles
  • Advertise
  • Contact us
 

 

Mail to: info@aceinfowayindia.com / Call : 91 11 9810018780

  • Article Written 
  • on 27.11.2009
  •  at 07:37 AM
  •  by admin

5 Steps to Write Better CSS Part II

This is the second part of 5 Steps to Write Better CSS. There are plenty of CSS tutorials are available on internet but the few tutorials are useful. In this tutorial you will find 5 steps to write better css code for your next website project. I hope you will enjoy this tutorial.

1. Keep CSS declarations in one line

you should always keep CSS declarations in one line, it helps in keeping your CSS file clean and smaller. It also helps to remove unwanted spaces and characters.

Good Code

h2 {font-size:18px; color:#333333; background:#cccccc; }

Bad Code

h2 {  font-size:18px;  color: #333333;  background: #cccccc; }

2. Combine Elements

One of the best way to save lines of code is by grouping selectors. There are some examples below of what I am referring to.

Good Code

h1, h2, h3 { font-family: Arial, Helvetica, sans-serif; color:#333;  }

Bad Code

h1 { font-family: Arial, Helvetica, sans-serif; color:#333; } h2 { font-family: Arial, Helvetica, sans-serif; color:#333;  } h3 { font-family: Arial, Helvetica, sans-serif; color:#333;  }

3. Use “Margin” to Center Layout

Many beginners to CSS can’t figure out why you can’t simply use float: center to achieve that centered effect on block-level elements. If only it were that easy! Unfortunately, you’ll need to use.

Code

#Container { margin:0 auto; /* top, bottom - and left, right*/ width:xxxpx;  }

4. Comment your CSS

It’s a great idea to comment your code in sections. To add a comment, simply add /* behind the comment, and */ to close it, like so:

Code

/******** CODE START HERE ********/

5. Use CSS Compress Tools

if you don’t want to waste your time in modifying your old style sheets you can simply use online css compress tools, it make your work in seconds.

check this online css compress tools…

Css Tidy

Clean Css

Css Optimiser

Flumpcakes Css optimizer

cssdrive Css Comperasor

W3C Css Validator


Conclusion

These are just some of the tips that help me to write better code. I hope that tutorial will also help you to write better and clean code. Apply these Tips to your current and next projects, and you will surely appreciate the efforts.

If You Think that tutorial can be more better , Please share with us. Comment us

if you would like to receive more tutorials from us, please consider subscribing to our feed by RSS or by email.

Filed under: Css, Tutorials by admin

Promote Us

  • Add to Mixx!
Ace Hosting India

Tags: Css ,Tutorials

Related Articles:

if you enjoyed reading this article, please check out other related articles below:

    • 5 Steps to Write Better Css
    • Creating a Image Gallery with Caption
    • Quick Tip: Easy Way To Create Drop Caps On Your Website
    • Tutorial to create a Beautiful, simple, horizontal CSS menu
    • Simple 2 column css layout
Untitled Document

10 Comments

  1. Revellsays on : November 27th, 2009 at 9:05 am Said:

    Hi,

    First of all, nice article! There aren’t many articles that address the writing style of CSS. I do have some thoughts on the first point though. In my opinion it’s better to use the long writing style while developing and have a script “minify” your CSS when using it on a live environment.

  2. Davesays on : November 27th, 2009 at 10:06 am Said:

    I completely disagree with point 1. When you’ve got 3 declarations, 1 line of code is great, but when there are 6 or 7, it gets really difficult to read.

    All that to save maybe 1KB? I don’t get it.

    Other than that one, some decent ideas here.
    Dave´s last blog ..2 more must-have CMS enabling plugins for WordPress My ComLuv Profile

  3. Nicolo' Fascesays on : November 27th, 2009 at 10:34 am Said:

    I agree with Dave, the point 1 is wrong, simply because if you work on a team it’s very difficult to read a one line code.

    You should also write the code in alphabetical order for the same purpose. ;)

  4. E.J. Semeijnsays on : November 27th, 2009 at 10:57 am Said:

    Why do we stop posting these tips? Internet is already full of these basics tips. And I also disagree with #1. It doesn’t make your code easier to understand, it just makes it more difficult.

    My tips would be to put the page structure in your CSS, make sections for RESET, HEADINGS, FORMS, HTML ELEMENTS, FONTS etc. That way your CSS will be easier to understand.

  5. safetycopysays on : November 27th, 2009 at 9:38 pm Said:

    I agree with several other people’s comments - point 1’s example of bad code is not bad code - it’s just an alternate style. This post would only be useful to complete newbies and we don’t want to start teaching them bad assumptions already!
    safetycopy´s last blog ..Photo My ComLuv Profile

  6. Joshsays on : November 29th, 2009 at 4:38 am Said:

    I do all of these except the last one. I don’t find it useful to compress my css, but unlike all of the previous readers I strongly agree on point #1. I just started writing my CSS in one line and it’s been tremendous. The scrolling has been far reduced. I guess this is a personal preference. Something that helps is that the editor I use wraps the code down to the next line so there is no horizontal scrolling.
    Josh´s last blog ..Addicted to Flickr My ComLuv Profile

  7. FAQPALsays on : November 29th, 2009 at 4:06 pm Said:

    Good beginner tips, I do not minify my CSS either, perhaps a much larger project would benefit from minifying, but the average site doesn’t really need to.

    As far as #1 goes, I think the wording is what is throwing people off, instead of saying, “Bad Code”, perhaps it should say like safetycopy has suggested, “Alternate Code”.
    FAQPAL´s last blog ..Bubble Effect with CSS My ComLuv Profile

  8. favSHAREsays on : November 30th, 2009 at 12:49 am Said:

    This article has been shared on favSHARE.net. Go and vote it!
    favSHARE´s last blog ..25 Web Layout Tutorials My ComLuv Profile

  9. Jean-Patrick Smithsays on : December 11th, 2009 at 11:15 am Said:

    I usually create a PHP file that includes all my css files, minifies it, and adds compression + expires headers.

    That way I don’t have to agree with point #1…

    What’s more important than having all your CSS on one line is reducing the number of HTTP calls with CSS sprites and combining all your CSS/JS into one file.

  10. SmashDesignsays on : January 8th, 2010 at 4:26 pm Said:

    Great toturial

    Thanks a lot
    SmashDesign´s last blog ..How to display HTML , CSS, Scripts code in your Blogger posts ? My ComLuv Profile

Submit a Comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>


CommentLuv Enabledshow more
« Free Postcard Textures
How to Create a Simple Green Button in Photoshop »
Untitled Document

    Subscribe

  • Subscribe to our feed
  • Subscribe by email
  • Follow us on Twitter
  • WooThemes - Where there's a Woo, there's a way!
  • DreamTemplate - Web Templates

    • Search

      Untitled Document
  • Calendar

    November 2009
    M T W T F S S
    « Oct   Dec »
     1
    2345678
    9101112131415
    16171819202122
    23242526272829
    30  
    • Pages

      • Home
      • About
      • Articles
      • Advertise
      • Contact us
    • Categories

    • Css (24)
    • Design / Inspiration (65)
    • Freebies (57)
    • Graphic Design (12)
    • Photoshop (32)
    • Resources (49)
    • Seo (1)
    • Tools (12)
    • Tutorials (42)
    • Typography (6)
    • Web development (6)
    • Wordpress (6)
    • Archives

    • February 2010
    • January 2010
    • December 2009
    • November 2009
    • October 2009
    • September 2009
    • August 2009
    • July 2009
    • June 2009
    • May 2009
    • Recent Posts

    • Css
    • Design / Inspiration
    • Freebies
    • Graphic Design
    • Photoshop
    • Popular Posts

    • How create good looking form without table
    • 5 Steps to Write Better CSS Part II
    • 21 Big, Bold Typography Website Design
    • How to Create Nice Scalable CSS Based Breadcrumbs
    • 20 Stunning Example Of Infographics For Your Inspiration
    • 33 "Hello" Pages Example For Your Inspiration
    • 30 Websites with Maximum Orange
    • Tag cloud

    Css Design Fonts Freebies Graphic Design Graphics Design Icons Inspiration Inspitation Photoshop Resources Tools Tutorials Typography Web development Wordpress

    • Friends

      • Abduzeedo
      • Alist Apart
      • Bittbox
      • CrazyLeaf Design
      • Css Tricks
      • David Walsh
      • Fudgegraphics
      • Fuel Your Creativity
      • Help Developer
      • Instant Shift
      • Line25
      • Mirificampress
      • My Ink Blog
      • Noupe
      • PSDFan
      • PSDtuts
      • Share Brain
      • Six Revisions
      • Spoon Graphics
      • Toxel
      • Vandelay Design
      • We function
      • Web Designer Depot
      • Web Designer Ledger
      • Web designer Wall
      • You The Designer
    • Community News

        • 15 Valentine’s Day Photoshop Tutorials

          Here is a roundup of 15 Photoshop tutorials to draw inspiration from, when designing your own pretty greeting card or wallpaper for your loved one.

          February 8, 2010
        • 36 Awesome Film Noir Movie Posters

          Film noir is a cinematic genre characterized by stylish Hollywood dramas that deal with the big issues of sex, violence and money. The noir world is full of morally dubious crooks, corrupt cops, in…

          February 6, 2010
        • Become A Logo Designer at Logomyway.com

          Need Amazing Custom Designs? LogoMyWay connects clients needing design work such as Custom logo designs, T-shirts designs, Business card designs and more to a thriving community of talented logo de…

          February 5, 2010
        • Showcase of E-Learning Websites for Interactive he…

          We are with something different today, as you seen below according to our title or article “Showcase of E-Learning Websites for Interactive help” this is totally new and too much demanding topi…

          February 4, 2010
        • 25+ Inspirational Tutorials of Valentine’s D…

          Saint Valentine’s Day is a holiday celebrated on February 14 by many people throughout the world. In the English-speaking countries, it is the traditional day on which lovers express their lo…

          February 2, 2010
        • 50+ Beautiful Wallpapers for Make more Romantic th…

          Saint Valentine’s Day is a holiday celebrated on February 14 by many people throughout the world. In the English-speaking countries, it is the traditional day on which lovers express their lo…

          February 1, 2010
        • 25 Ultimate Useful Form Tutorials Using CSS and Ja…

          In this article I just featured many good looking contact forms, so you should know how the contact form is good looking. Now let’s take a look how to create outstanding and beautifully designed …

          February 1, 2010
    • Add News

      You can submit your links below using the form and they will usually be approved within a few hours.






      Loading...

    • Translator

      English flagItalian flagKorean flagChinese (Simplified) flagChinese (Traditional) flagPortuguese flagGerman flagFrench flagSpanish flagJapanese flagArabic flagRussian flagGreek flagDutch flagBulgarian flagCzech flagCroat flagDanish flagFinnish flagHindi flagPolish flagRumanian flagSwedish flagNorwegian flagCatalan flagFilipino flagHebrew flagIndonesian flagLatvian flagLithuanian flagSerbian flagSlovak flagSlovenian flagUkrainian flagVietnamese flagAlbanian flagEstonian flagGalician flagMaltese flagThai flagTurkish flagHungarian flag
  • SPONSORS

    Check out UPrinting on YouTheDesigner.


    Business Cards Online

    Web Design Blog Directory

.
Untitled Document
Back to top

General

These maybe of some interest
  • About Our Company
  • Testimonials
  • Contact Details
  • Blog
  • Social - Twitter, Flickr

Works

Examples of past projects
  • About Our Company
  • Testimonials
  • Contact Details
  • Blog
  • Social - Twitter, Flickr

Services

This is what where selling today
  • About Our Company
  • Testimonials
  • Contact Details
  • Blog
  • Social - Twitter, Flickr

Contact Details

Want to hire us? get started here...
  • Free Project Assesment
  • Email - info@aceinfowayindia.com
  • Tel: 91 11 9810018780

Copyright © 2009, All Right Reserved, Ace Infoway India                                                      Hire Ace Infoway India for your next design project. View our portfolio.