Snook’s CSS tips

Snook has some good tips for coding and managing CSS. Here are my thoughts on each.

px for font sizes

Absolutely. I’ve tried ems and they are more hassle than they are worth. Percentages are too finicky and small/medium/large/etc. is too imprecise. Offer people alternate stylesheets with bigger font-sizes for accessibility in browsers like IE6 that don’t resize px sized fonts.

CSS declarations on one line

I understand Snook’s point but my text-editor supports code-collapsing and putting it all on one line makes it hard to decipher complex styles. Plus I usually use find to navigate my CSS.

Blocking the Styles

Very good advice. I also comment the blocks which makes a find operation really simple. Snook’s comment on not overriding browser defaults is also a good one.

Browser Support

Sadly I just can’t do this. Too many IE5.5 users still on my logs. Though I find stopping at that level makes for only a few cross-browser issues anyway.

Allow Block Elements to Fill Their Space Naturally

Amen to that. Often you don’t even have to think to do this, it is a by product of good HTML structure in many cases.

Use CSS Shorthand

I am mixed on this. Margin absolutely should be short-hand but font or background I often break up. Too many times has a URL problem broken the rest of a background declaration. I think that if you put everything on one line then it is easier to use shorthand.

Avoid Unnecessary Selectors

Definitley. Especially avoid div#content and use #content. It lets you swap to different elements and allows multiple uses of a class on different elements.

 

Trackbacks

(Trackback URL)

close Reblog this comment
blog comments powered by Disqus