When using box-sizing: border-box
in Safari, there is a bug affecting the height of an img
element when using height: 100%
and a padding on the parent element.
See this fiddle and test it on Chrome/Firefox versus Safari to see the difference: https://jsfiddle.net/Arko/66b9bt02/1/
Here is the full code for reference:
HTML:
<div>
<img src="http://placehold.it/40x40">
</div>
CSS:
* {
box-sizing: border-box;
}
div {
padding: 15px;
height: 50px;
}
img {
height: 100%;
}
With border-box sizing, the img height should be 20px (50px div height minus 2x 15px padding). This is correct in Chrome and Firefox. But Safari displays the image at 30px height.
I found no other instance of this issue reported. Is this a new webkit bug to be reported? Or am I missing something?
(Tested in Safari 9.1.1 and Webkit Nightly 202811)
Add a wrapper for image with height 100%, padding 0:
https://jsfiddle.net/vgdz2Loj/
<div>
<div class="wrapper">
<img src="http://placehold.it/40x40">
</div>
</div>
.wrapper {
height: 100%;
padding: 0;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With