Build Easy

Thursday, September 28, 2006

title icon11 good practices of CSS

CSS can be very flavorful, you can design a saucy website without even a single image if you are well versed in it. Yes, that's possible, only if you get to know every kiosk and trap of it with each of the major browsers. It can be quite tricky, and takes experience and experiments. Some of the good practices of CSS I know are:


  1. Link pseudo-classes a:link, a:visited, a:hover, and a:active should always be ordered as a:link -> a:visited -> a:hover -> a:active, or L(O)V(E)/HA(T)(E) for the sake of memorization.
  2. First give those common tags of HTML a good treat before fabricating more specific IDs and classes: body, h1, h2, h3, h4, h5, h6, p, table, thead, tbody, tfoot, th, td, blockquote, a, img, pre, form, and so forth.
  3. Classes are used in situations where more than one peer texts or blocks are stylized the same way, otherwise, if the presentational target is unique throughtout each page, use IDs.
  4. Don't rely on IDs excessively, though, in that it hampers the debugging. To simplify the selectors for clarity, type in the form of tag#ID/.class tag tag:pseudo, or something like that. In a word, try not to complicate, and use selectors as short as possible.
  5. Stylize shared semantic components of your pages in different CSS files, and import them together into one core css file which is referred to from the head part of each of your pages. Or at least, separate the layout information from the in-line visuals.
  6. CSS rules specifically designed for a single or group of HTML files will be imported to them from the head part in a separate file, like this:

    <style type="text/css">
    @import url(/css/specific.css);
    </style>


  7. Don't quote the url when you want to set the background to an image. It's the same under other similar circumstances when specifying a url in CSS.
  8. Use hybrid rules rather than separate ones, except for when you insert an exception after a collective prescript.
  9. Use relative sizes em for fonts rather than absolute ones as px, pt, and so forth.
  10. Don't make your CSS files look too fat, write casual styles directly in HTML files with a style="" property. It's totally acceptable.
  11. Put different selectors together for a combined stylization where necessary. This helps your CSS files look neat.

This is the most unprofessional advice ever offered about the good practices of CSS, help yourself and be my guest, comment as you like!

»Post a Comment

0 Comments:

»Post a Comment

Links to this post:

Create a Link

« Home