Not
everyone writes CSS the same way and there is no particular "right"
way to do it. The W3C have set the standards but beyond this,
writing CSS is down to an individual's preferences. Here are 4
quick tips and ideas that you can use to make your CSS more
streamlined, maintainable and easy to read.
1: Make a
table of contents
At the top
of your CSS document, write out a table of contents. For example,
you could outline the different areas that your CSS document is
styling (header, main, footer etc). Then, use a large, obvious
section break to separate the areas. Not only does this make your
CSS look neater, but when it comes to making quick adjustments to
certain areas of your website at a later date, finding the
corresponding area in your CSS will be much easier.
2: Separate the positioning properties from the typographic properties
Why? Mostly
for the obsessive-compulsive neatness of it all, but also because
you are likely to reuse lots of typographic properties. If you mix
typographic / positioning properties in your CSS document, you
might find you're needlessly repeating yourself.
3: Isolate single properties that you are likely to reuse a lot
If you find
yourself using a single property a lot, isolate it to save yourself
repeating it over and over again and also enabling you to change
the display of all parts of the site that use it.
4: Learn to exploit the cascading nature of CSS
This one is
an obvious one, but it's sometimes overlooked. Say you have two
similar boxes on your website with only minor differences - you
could write out CSS to style each box, or you could write CSS to
style both at the same time, then add extra properties below to
make one look different.

Post Comments