Re: margins, ems and context

Le Mar 25 janvier 2011 6:51, Niels Matthijs a écrit :
> Just wondering,
>
> currently the box-model states that margins are integral part of the
> box. This means that when you change the font-size of a css box, margins
> defined in ems will change too.

Correct.

> This is more often than not (never ran
> into a situation where I was actually happy with it, but who knows ...)
> unwanted behavior. You usually want margins of a box to match themselves
> to the font-size of its parent box (creating a clean vertical grid).

If I understood you correctly...

Then define the margins of the parent box with em unit and then set the
margin of the child box with inherit keyword. The inherited margin values
will be those as set for the parent box in ems, therefore using the
font-size of the parent.

A change of font-size on the parent box will scale/impact/influence
accordingly the margin of the child box. Then, if applicable, you have to
watch for/consider margin collapsing. This is maybe what you're missing
here. Vertical adjoining margins do/can collapse unless there is a border
or padding separating them.

> One difficulty has been pointed out by a commenter on my blog, who
> states that the setup changes when a box is absolutely positioned,
> though in that case it sounds quite reasonable to match em-margins to
> the font-size of it's reference block (the pos:abs/pos:rel block closest
> above).
>
> I know it's not feasible to just change the way the css box model works,
> one option would be to introduce a new css property (much like
> box-sizing, could be box-calculate?).

No need to create a new css property here...
And rem is the unit referring to the font size of the root element anyway,
which is not necessarly the parent element.
http://www.w3.org/TR/css3-values/#relative0

And as pointed out by Anton Prowse, why would horizontal margins dependent
on the font size of the containing block be useful?

regards, Gérard
-- 
CSS 2.1 Test suite RC5 (January 11th 2011)
http://test.csswg.org/suites/css2.1/20110111/html4/toc.html

Contributions to CSS 2.1 test suite
http://www.gtalbot.org/BrowserBugsSection/css21testsuite/

Web authors' contributions to CSS 2.1 test suite
http://www.gtalbot.org/BrowserBugsSection/css21testsuite/web-authors-contributions-css21-testsuite.html

Received on Tuesday, 25 January 2011 18:48:12 UTC