Resetting CSS default padding and margins
I’ve started work on a new site this week and one of the things I stumbled upon was a nifty method for reseting the default values of potentially any CSS property. This is especially useful because each browser has different ‘default’ settings (such as padding and margins).
In extreme cases browsers will position HTML elements using different CSS properties, for example IE uses margin-left to indent lists, while firefox (or rather its engine) uses padding-left. This code:
* {
padding:0;
margin:0;
}
will reset all spacing default properties. Excellent! However now we have to manually set all the margins and padding of our ‘H1->Hx’ elements, a potentially lengthy process. However we can rectify this by assigning several elements properties in one go.
h1, h2, h3, body {
margin: 10px;
padding: 10px;
}
Obviously these are only simple examples, but this is one technique I will be using in all of my websites from now on… if you are interested in further reading, this is an invaluable link ‘Eric Meyers, CSS Legend‘.