Flex elements ignore percent padding in Firefox

See https://lists.w3.org/Archives/Public/www-style/2015Sep/0038.html

Grid/Flex Percentages

  • The group tried to work through how vertical percentage margins
    and paddings are defined.

    • Note: Top and bottom margins in CSS have traditionally
      resolved against the containing block width instead of its
      height, which has some useful effects but is generally
      surprising. Existing layout modes must of course continue
      to do so.
    • Previous group resolution had been for option 2 (below), but
      Google felt they had new information regarding abspos
      behavior that merited reconsideration.
    • The discussion came down to three potential solutions:
      • Option 1: Always resolve percents against the width.
      • Option 2: Grid and flex resolve against height, and
        abspos items always resolve against the width.
      • Option 3: Grid and flex, including their abspos items,
        resolve against the height. Abspos elsewhere
        continue to resolve against the width.
    • In a straw poll the group was pretty evenly divided between
      options 1 and 3.
    • Microsoft would object to option 1 and Google to option 3,
      so the discussion reached an impasse and will be continued
      privately during the F2F in hopes of reaching a conclusion.

See https://lists.w3.org/Archives/Public/www-style/2015Sep/0113.html,

Flexbox % Follow-Up

  • […] there was still no conclusion.

The current Flexbox spec warns about this:

Percentage margins and paddings on flex items can be resolved
against either:

  • their own axis (left/right percentages resolve against width, top/bottom resolve against height)
  • the inline axis (left/right/top/bottom percentages all resolve against width)

A User Agent must choose one of these two behaviors.

Note: This variance sucks, but it accurately captures the current
state of the world (no consensus among implementations, and no
consensus within the CSSWG). It is the CSSWG’s intention that browsers
will converge on one of the behaviors, at which time the spec will be
amended to require that.

Authors should avoid using percentages in paddings or margins on flex items entirely, as they will get different behavior in
different browsers.

However, more recently the CSS WG resolved (with some controversy):

Both flexbox and grid items top and bottom margin and padding percent resolves against the available inline direction.

See the updated editor’s draft.

Leave a Comment