Borris <no**@none.co m> wrote:
<div style="backgrou nd-color: blue; width: 500px; height: 300px">
<div style="backgrou nd-color: red; margin-top: 100px; margin-left: 100px; width:
300px; height: 100px">
</div>
</div>
Where will the red box be positioned? Even experienced web developers often
expect it to be in the middle of the blue box, but instead (on
standards-compliant browsers) the blue box is lowered to line up its top edge
with that of the red box. This is because of collapsing margins
(http://www.w3.org/TR/CSS21/box.html#...sing-margins); the top margins of
both boxes are adjacent, so the larger margin (100px) is applied to both.
I humbly propose that this is a design fault. Collapsing margins only seem to
make sense when top and bottom margins are adjacent;
The problem is that it is the right behaviour if you meticulously
analyze the specs, whether the effect was foreseen when the spec rules
were established I do not know, but changing the spec rules
retrospectively because some rule has an unforeseen effect doesn't
strike me as viable.
in what proportion of cases
to designers want the top margins of nested blocks to collapse?
Probably never, it's just another example where the specs fail to do
what people expect, CSS in general suffers from this. I've long been of
the opinion that CSS has failed in a fundamental way: it's far to
difficult to use for the people who are meant to be using it, i.e.
designers and private/amateur web authors.
The problem could have been mitigated if early on there had been good
quality visual authoring software that would have taken care of the
technical details. Problems like the above, combined with (arguably the
resulting) browser non spec compliant rendering have significantly
contributed to preventing that from happening. Designers are therefore
often still very weary of CSS because it requires them to do something
that they are often genetically ill equipped to do: get technical.
The ludicrous situation is that the techies who *are* equipped to handle
CSS and it's idiosyncratic rules are the people who typically don't have
a clue when it comes to design and styling. (I count myself amongst
these)
Unfortunately we seem to be stuck with CSS and it's fundamental
failures. Like with the errors that were made with HTML, some mistakes
are nigh impossible to correct once they have been made. Mind you, the
wrong people continue to be in charge of CSS (the techies), so the view
that CSS is fundamentally flawed is not a popular one, even if it were
possible to re-engineer the language it probably wouldn't happen.
--
Spartanicus