Consider the following three scenarios...
Scenario A
@import "reset.css";
/* ... */
p {margin:1em 0;}
/* ... */
p#copyright {margin:0; padding:10px;}
In Scenario A, a generic rule is applied to all <p>
elements that gives it top and bottom margins, so that the paragraphs are properly spaced when used in the HTML. But, by doing so, this causes cases where a <p>
element now needs its generic margins removed for decorative purposes, e.g. the Copyright at the foot of the document must have no margins.
Scenario B
@import "reset.css";
/* ... */
div.content_body p,
div.sidebar_body p {margin:1em 0;}
/* ... */
p#copyright {padding:10px;}
In Scenario B, it is assumed that <p>
elements don't need top and bottom margins unless explicitly defined. Here the Content and Sidebar elements will need well-spaced paragraphs
Scenario C
@import "reset.css";
/* ... */
p.spaced {margin:1em 0;}
/* ... */
p#copyright {padding:10px;}
In Scenario C, only <p>
elements with a class spaced
will have top and bottom margins applied.
Questions:
Which is the better scenario to use, and more importantly why? What impact does each scenario have on:
- browser CSS performance
- CSS weight and maintainability
- the proliferation of UI defects
If you had to add a new widget that needed flowing paragraphs, which scenario would be better for you?
Thanks!