I'm trying to add padding to an element inside a display:flex
element. When the padding is defined as a percent, it doesn't display in Firefox, though it does when defined in px
. Both cases work as expected in Chrome.
div {
background: #233540;
}
div > div {
color: #80A1B6;
}
.parent {
display: flex;
}
.padded {
padding-bottom: 10%;
}
<div class="parent">
<div class="padded">
asdf
</div>
</div>
Chrome:
Firefox:
Edit: This may be because of Mozilla's decision to interpret vertical percentages with respect to the height of the parent container. Seems crazy to me. https://bugzilla.mozilla.org/show_bug.cgi?id=851379
Edit 2: Yes, it appears that the spec actually defines vertical padding and margin as being resolved against the container's height, so perhaps Chrome is the one not honoring the spec? https://drafts.csswg.org/css-flexbox/#item-margins
The current draft spec says
So, Firefox is now incorrect according to the latest draft.
CSSWG discussion: https://github.com/w3c/csswg-drafts/issues/2085 Spec changelog reference: https://drafts.csswg.org/css-flexbox/#change-2017-margin-padding-percent Current spec on flex item margins: https://drafts.csswg.org/css-flexbox/#item-margins
Try this:
See https://lists.w3.org/Archives/Public/www-style/2015Sep/0038.html
See https://lists.w3.org/Archives/Public/www-style/2015Sep/0113.html,
The current Flexbox spec warns about this:
However, more recently the CSS WG resolved (with some controversy):
See the updated editor's draft.
For me this does the trick: adding display: table to the div. Don't know if that causes other problems though.