W3C home > Mailing lists > Public > www-style@w3.org > January 2011

Re: margins, ems and context

From: Gérard Talbot <www-style@gtalbot.org>
Date: Tue, 25 Jan 2011 10:47:35 -0800
Message-ID: <023646e22b042c73de50293babb16c3c.squirrel@cp3.shieldhost.com>
To: "Niels Matthijs" <niels.matthijs@internetarchitects.be>
Cc: "W3C style mailing list" <www-style@w3.org>

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.


> 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.

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)

Contributions to CSS 2.1 test suite

Web authors' contributions to CSS 2.1 test suite
Received on Tuesday, 25 January 2011 18:48:12 UTC

This archive was generated by hypermail 2.4.0 : Friday, 25 March 2022 10:07:55 UTC