Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IE CSS bug: IMG original height affecting parent height

I've got a PARENT flexbox div (which is also part of a column flexbox):

div.flex_block {
        width:100%;
        flex: 1 1 auto;
        display:flex;
        flex-direction:row;
        align-items:center;
        justify-content:space-between;  
        padding-bottom:30px; 
}

It contains 2 children:

.flex_block  .content{
    max-width:none; /* override other code */
    flex: 0 1 50%;
}

.flex_block  .image{
    max-width:none; /* override other code */
    flex: 0 1 35%;
}

The first child has some text in it. The second has an oversized image, that is set to 100% width, so it shrinks to its container.

.flex_block  .image img{
    display:block;
    width:100%;
    height: auto;
}

It works as expected in Chrome, but in IE the original img's height seems to expand the PARENT container (even though it does shrink to fit its container). If I set the img height, the problem is fixed. AUTO doesn't fix it. I need this as a responsive design, obviously, so I don't wish to set the height in pixels.

Here is a visualisation of what happens: enter image description here

I've also tried using inline elements with percentage widths instead of a flexbox, but the issue prevailed.

like image 539
toms Avatar asked Oct 26 '15 16:10

toms


People also ask

How do you make a parent DIV the same height as a child?

Using height: auto or using min-height on parent element will work. And for avoiding horizontal scrollbar, which can be caused due to padding or border can be avoided by using box-sizing: border-box on child element or overflow: hidden on parent element.

How do I fix a stretched image in CSS?

1.1.When you added max-width: 100%; to any image, the width will be adjusted automatically based on the outer element width and you know what height: auto; does as it's self-explanatory. This is the fix we have been using for years to prevent image stretching in our sites.


1 Answers

A possible solution to add to container:

flex-shrink: 0;

Or more specific to IE11:

-ms-flex-negative: 0;

This seems to have fixed my issue, but your results may vary.

I don't pretend to understand why it works, but it seems to be working for me. :)

like image 177
JonMcL Avatar answered Sep 21 '22 02:09

JonMcL