Open Loirooriol opened 1 year ago
Blink recently changed this to fix a bug - and now behave like gecko (partially due to the round-tripping issue you describe).
Ian
So checking latest Blink I see that it always resolves auto
to 0px
(unlike Gecko, even if there are no floats).
This still doesn't round-trip: setting both margins to 0px in the example would place the element adjacent to the float instead of being separated by 25px.
Blink changed again in https://chromium-review.googlesource.com/c/chromium/src/+/4930440 and aligned with Servo (option 1 above), which I think is the most reasonable behavior.
So Agenda+ to resolve on it. In particular:
auto
margins align within the free space after taking floats into account.getComputedStyle
. There is the remaining question of only doing it for auto
(like Blink) or in all cases (like Servo).The CSS Working Group just discussed [css2][css-flow][cssom] How does avoiding floats affect margins?
, and agreed to the following:
RESOLVED: Auto margins align between the remaining space after accounting for floats (existing interoperable behavior)
RESOLVED: For elements with a principal box, getComputedStyle always returns used values
RESOLVED: We'd like resolved margins to round-trip
https://drafts.csswg.org/css2/#floats
So the vertical adjustment to avoid floats is done with clearance, but what mechanism is used for the horizontal adjustment?
I see 2 reasonable options:
The thing is that
getComputedStyle
exposes the used margins: https://drafts.csswg.org/cssom/#resolved-value-special-case-property-like-heightHowever, note that for Gecko, Blink and WebKit, the used value is only for a computed
auto
. For a computed<length-percentage>
, they just absolutize it into a length, even if there is over-constrainment and the used value is a different amount. Servo still provides the used value even for a computed<length-percentage>
.Then, consider
Note that this is not clear in CSS2, but on all browsers the
auto
margins center the element within the space next to the float, not within the containing block:This is what browsers say:
0px, 0px
.auto
is typically resolved to the used value, but just to0px
in the presence of floats.50px, 50px
. Just resolvesauto
according to https://drafts.csswg.org/css2/#blockwidth, ignoring floats, without taking floats into account, even if the layout is completely different.25px, 75px
. It resolvesmargin-left: auto
to the space between the rightmost left float to avoid and the border (like option 2 above). But then it resolvesmargin-left: auto
according to https://drafts.csswg.org/css2/#blockwidth, ignoring floats.75px, 25px
25px, 25px
The behaviors of Gecko, Blink and WebKit seem nonsensical to me.
Also, if we want round-tripping, we must go with option 1 (or change how
auto
behaves in the presence of floats, but that seems more risky for compat).