» 5 Steps to Write Better Css
  • Home
  • About
  • Articles
  • Advertise
  • Contact us
 

 

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

  • Article Written 
  • on 16.09.2009
  •  at 06:26 AM
  •  by admin

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. ResetCss

You should always use reset Whether it can be Eric Meyer Reset, the YUI Reset, or your own custom reset, just use something.

The goal of a reset stylesheet is to reduce browser inconsistencies in things like default line heights, margins and font sizes of headings, and so on – Eric Meyer

html, body, div, span, applet, object, h1, h2, h3, h4, h5, h6, iframe,  blockquote, pre, abbr, acronym, address, big, cite, code, del, dfn, em,  font, img, ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, dd, dl, dt, fieldset, form, label, legend, table, caption, tbody, tfoot,  thead, tr, th, td, input, select, textarea   {margin:0; padding:0;}
*{margin:0; padding:0;}

2. CSS Shorthand

One of the best and important feature of CSS is the ability to write code in a minimized way.

Incorrect Code

{ margin-top:10px; margin-right:7px; margin-bottom:10px; margin-left:7px; padding-top:10px; padding-right:7px; padding-bottom:10px; padding-left:7px; font-size:12px; font-weight:bold; font-family: Arial, Verdana, Tahoma, sans-serif; }

Correct Code

{ margin: 10px 7px 10px 7px; padding: 10px 7px 10px 7px; font:bold 12px Arial, Verdana, Tahoma, sans-serif; }

3. Don’t using so many classes and Id’s

I have noticed that most of the beginners add classes and ID’s to almost every element on the page, which is not required.There are some examples below of what I am referring to.

Incorrect Code

<div id="wrapper" class="wrapper">   <p class="heading"><strong class="subheading">Welcome</strong></p>   <p class="linka"><a href="#" class="link">Home</a></p>   <p class="linkb"><a href="#" class="link">About</a></p>   <p class="linkc"><a href="#" class="link">Services</a></p>   <p class="linkd"><a href="#" class="link">Contact</a></p> </div>

Here is the correct code

Correct Code

<div  id="wrapper"> <h1>Welcome</h1>           <ul>                  <li><a href="#">Home</a></li>                  <li><a href="#">About</a></li>                  <li><a href="#">Services</a></li>                  <li><a href="#">Contact</a></li>          </ul> </div>

4. Organization you Stylesheet

You should organize your stylesheet so that it is easy to find things and related items are close together. Use comments effectively. For example, There is the Example will tell you how to organize your stylesheet

/*Reset*/ Remove margin and padding elements /*Basic Elements*/ Define style for basic elements: body, h1, h2, h3, h4, h6, ol, ul, dl, p etc. /*Generic Classes*/ Define style for generic classes: simple things like remove the bottom, floating to the sides etc. /*Basic Layout*/ /*Basic Layout*/   Define the style for basic layout: header. footer, sidebar etc. /*Header*/ Define the style for header /*Content*/ Define the style for content area /*Footer*/ Define the style for footer /*Etc*/ Continue

5. Use Conditional Stylesheets

Internet Explorer is the most buggy of all browsers. Fortunately you can use conditional comments to manage the CSS that is served to IE. If I need it I have a stylesheet called ie6.css that targets older versions of IE. It allows me to manage CSS for older browsers quickly and easily.

Here is the Example

<!--[if lte IE 6]>         <link rel="stylesheet" href="ie6.css" type="text/css" media="screen" />         <![endif]-->

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 inspiration 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:

    • How to Create Your Own Simple Reset.css File
    • Simple 2 column css layout
    • 5 Steps to Write Better CSS Part II
    • 5 Simple Ways To Keep Your Code Friendly
    • Tutorial to create a Beautiful, simple, horizontal CSS menu
Untitled Document

6 Comments

  1. Tim Wrightsays on : September 16th, 2009 at 3:13 pm Said:

    Overall, really good tips. Generally, we don’t use the universal selector ( * ) to reset margin and padding because form elements are so unstable cross-browser it does more damage than good.

    But if you’re writing a site without any forms, I say, absolutely use it.

    Good post, thanks

  2. Karlsays on : September 17th, 2009 at 10:22 am Said:

    Well example number three is basically right. Though I can’t recall using the same name for id and class being wrong (never tried it, never stumble upon an example) it appears very stupid and messy.

    But giving individual identifiers to navigation elements is necessary if you want to highlight a current item via css. This example is maybe not the best to be shown and may confuse beginners as bad or wrong habit/code.

  3. neelsays on : September 17th, 2009 at 3:19 pm Said:

    Nice article for CSS coding. Yes a well organized stylesheet is always good for browser compatibility as you dont have to check it again.

  4. No universal selectorssays on : September 17th, 2009 at 8:16 pm Said:

    universal selectors are very bad!

  5. timsays on : September 30th, 2009 at 2:14 pm Said:

    Example 3 can be difficult if you want to show your visiotrs on which site they are right now. There’s no way around IDs then.

  6. Amol Nirmala Wamansays on : December 3rd, 2009 at 12:04 pm Said:

    more better way of shortening CSS code:

    {
    margin: 10px 7px; /* TRiBLe method */
    padding: 10px 7px; /* TRiBLe method */
    font:700 12px Arial, Verdana, Tahoma, sans-serif; /* bold=700 */
    }

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
« A Massive Collection of Free and Premium Wordpress Theme Websites.
How to Create Letterpress Typography 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

    September 2009
    M T W T F S S
    « Aug   Oct »
     123456
    78910111213
    14151617181920
    21222324252627
    282930  
    • 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.