Monday, September 13, 2010

Zeroing margins and padding on all elements

Although the previous block of code is clean and efficient, it isn’t something I use in my
websites. The reason for this is that browsers place default (and sometimes varying)
margins around various elements other than the page’s body, too. Therefore, my CSS
boilerplates always include the following:
* {
margin: 0;
padding: 0;
}
The selector, *, is the universal selector, and the declaration therefore applies to all elements
on the web page. In other words, add this rule to your CSS, and all default margins
and padding for all elements are removed, enabling you to start from scratch in all
browsers and define explicit values for those elements that need them.

No comments:

Post a Comment