I have a flex item, image-container
, that contains an image:
<div class="container">
<div class="image-container">
<img class="image" src="image.jpg"></img>
</div>
</div>
I want image-container
and image
to have equal width and height but I don’t want their height to exceed the height of the window so I tried the following CSS:
html,body,#root {
height: 100%;
padding: 0;
margin: 0;
}
.container {
display: flex;
flex-direction: column;
align-items: start;
height: 100%;
background-color: orange;
padding: 10px;
}
.image-container {
display: flex;
min-height: 0;
background-color: blue;
}
The problem is image-container
has a width that is much larger than image
.
2
Answers
One possible solution is setting the image container to inline-block and the image to block, optionally set a width to the image:
Fiddle
Just remove
min-height: 0;
from.image-container
and it will be fixed