Using CSS For Better Coding

Reference | in ,,, | by Kabir Bedi

Messy CSS is one of the most common complains developers have. And more often that not it is the result of a bad coding job that has been done. However, writing clean and manageable CSS is not a difficult job when you know how to go about things.nHere ares some tips that will helps you write slimmer and faster CSS and also ease the process of the same.nBe OrganizednOrganization is important in all the processes of the design and development procedure. Use a coherent structure instead of randomly specifying id’s and classes. This subsequently helps the stylesheets to benefit from the style inheritance. Always specify your most generic forms before the non-generic ones so that your CSS can inherit attributes properly. This will make it much more easier to edit the CSS later on and make any changes there.nSpecify the CredentialsnDon’t forget to assign the time, date and sign credentials for your CSS. Its important to let people know who wrote your CSS, the date when it was written and who can be contacted in case of any queries. This becomes especially useful when you design templates or themes.nSave TemplatesnWhen you finalize the structure of the CSS, remove all the non-generic elements and save the file as a CSS template that can be used afterwards also. In fact, you can save a number of templates as and when you create something different. For example, two-column layout, mobile, print etc. When you have saved templates you would not have to re-write each and every stylesheet. Instead, you can just make some changes on the template and customize them for use.nUse Naming ConventionsnInstead of specifications like col-left and col-right, use some generic naming conventions using alpha, beta etc. This avoids any confusion in the HTML and makes it easier for you to alter the positions of the same. CSS allows for the separations of style from the content which further enables you to redesign an entire website just by modifying the CSS. This is why it is important to use versatile and consistent naming conventions.nUse Hyphens in place of UnderscoresnOlder browsers don’t render well when CSS contains underscores and don’t support them either. Therefore, it is always better to use hyphens in order to gain some compatibility.nnAvoid RepetitionnInstead of specifying the styles again and again, learn to re-use the CSS attributes by grouping elements together. For example, if all your h1 and h2 elements have the same font size, colors and margins, it would be better ti group them using a comma instead of repeating it over and again.nOptimize furthernWhen you have lightweight stylesheets, your website would load faster and also it would be easier to maintain and make updates. The most important thing while shrinking the size of stylesheets is trimming off whatever you don’t need and them merging similar items under groups. Also, you can skip specifying a unit if measure when using 0. This is because zero is always zero by default irrespective of the unit of measure.nKabir Bedi is a senior web consultant at LeXolution IT Services, a reputed offshore web design company based in India. The company specializes in providing a variety of web services like web design & development, website maintenance services and internet promotion.

No related posts.

OLDER:

NEWER:

Leave a Comment

Most Recent Posts

Read Back Issues of WHIR Magazine

  • Thumbnail image for The Social Media Issue

    May 2012 - The Social Media Issue

    Read the Digital Edition – It seems rather serendipitous that, as we began preparing to launch this social media focused issue of WHIR magazine, the WHIR organization, and other iNET Interactive editorial properties began working in earnest to measure and track engagement as a metric on our websites and on the content we publish.

    Read The Digital Edition
  • Thumbnail image for 2012 Hottest Hosts Directory

    February 2012 - 2012 Hottest Hosts Directory

    Read the Digital Edition – This edition of our Hottest Hosts buyer’s guide and directory issue is the fifth instance of the annual publication, a milestone that kind of snuck up on me, personally, but which I think provides an intriguing validation of the format, and of the principle behind it. The hosted services industry …Read More

    Read The Digital Edition
  • Thumbnail image for The Killer Business Model

    October 2011 - The Killer Business Model

    Read the Digital Edition – In pursuit of some inspiration for your killer business model, we sought out some of the really cool things being done in the hosting space by providers trying to stand out from the crowd. They’re not all huge companies yet, but they’ve all got some really interesting ideas, and more importantly, they’re looking at innovating in a way that could inspire some really original thinking from you.

    Read The Digital Edition