Using advanced CSS 2 selectors, another solution would be possible that does not rely on a class last
to introduce layout info into the HTML.
The solution uses the adjacent selectors.
Unfortunately, MSIE 6 doesn't support it yet so reluctance to use it is understandable.
h1 {
margin: 0 0 1em;
}
div, p, p + h1, div + h1 {
margin: 1em 0 0;
}
This way, the first h1
won't have a top margin while any h1
that immediately follows a paragraph or a box has a top margin.