The LHS flex child in this example has 1em padding, and it will cause RHS to overflow the parent:
<div style="display: -ms-flexbox; box-sizing: border-box; width: 200px; border: 5px solid black">
<div style="padding: 1em; -ms-flex-positive: 0; -ms-flex-negative: 0; -ms-flex-preferred-size: 33%; background-color: blue; box-sizing: border-box">
LHS
</div>
<div style="-ms-flex-positive: 0; -ms-flex-negative: 0; -ms-flex-preferred-size: 67%; background-color: red; box-sizing: border-box">
RHS
</div>
</div>
Here's the fiddle:
How can I eliminate the overflow when flex children have padding? box-sizing: border-box
doesn't work.
I had similar problems with
flexbox
andbox-sizing: border-box;
. The latter one just doesn't seem to work in IE. Width wouldn't work in this case since padding will change it - but if you can usemax-width
, that should fix the problem.In IE
flex-basis
doesn't account forbox-sizing:border-box
. It's a know bug as described here: https://github.com/philipwalton/flexbugs#7-flex-basis-doesnt-account-for-box-sizingborder-boxThough it has been fixed in Edge now.
Some fixes:
flex-basis: calc($basisValue - $paddingValue)
← this worked best for meflex-basis: auto
max-width: $value
The issue appears to be the value for
-ms-flex-negative: 0
on the box that has the padding, if this is set to 1, it appears to work.The background of RHS will now remain within the box, however its content won't, although it's the same with LHS. Adding
max-width: 100%
to LHS fixes that, but not on RHS, but addingword-break: break-all
then causes the content to break and remain within the RHS box.Fiddle
Is this what you want?
I don't have access to IE10, but in IE11, I had to explicitly set flex-basis to auto:
I was able to solve this by adding:
So this combination worked, even when using
autoprefixer
:The calc value handily overrode the auto-generated prefixes, only noticed by IE.