I have a situation where I need an image to expand to the size of it's container, which is a flex box and cannot have a fixed height.
The direct container is nested inside a few layers of flexboxes, and the outer layer needs to be at a height of 80vh.
I see that the image does not resize vertically when the container has heights and widths set as a percentage. Does anyone have a work around for this? I need a consistent solution for several images with a wide range of aspect ratios (some portrait, some landscape).
Thanks!
See below for Code and CodePen link: https://codepen.io/anon/pen/NgZByM?editors=1100
<div class="wrapper">
<div class="imperial-image-wrap">
<section class="imperial-image-card">
<div class="image-icon-container">
<div class="previous">
</div>
<figure>
<img src="http://ghk.h-cdn.co/assets/16/09/980x490/landscape-1457107485-gettyimages-512366437.jpg" />
</figure>
<div class="next">
</div>
</div>
<section class="action-icons">
<span>This is a fixed with</span>
</section>
<div class="asset-description">
<div class="asset-title">
<span>This needs the ability to expand to fit it's content, which is variable.</span>
</div>
</div>
</section>
</div>
<div class="buy-details">
<span>This is where the details go</span>
</div>
</div>
.wrapper {
display:flex;
height: 80vh;
}
.buy-details {
width: 350px;
padding: 10px;
border: 1px solid black;
}
.imperial-image-wrap {
width:calc(100%-350px);
height:80vh;
}
.imperial-image-card {
height:100%;
display:flex;
flex-direction: column;
}
.image-icon-container {
flex:2 1 auto;
display:flex;
}
.action-icons {
border: 1px solid purple;
display:flex;
justify-content:center;
min-height: 15px;
}
.asset-description {
width: 100%;
border: 1px solid red;
}
.previous, .next {
min-width: 15px;
border: 1px solid red;
}
figure {
display:flex;
flex-direction: row;
width: 100%;
height: 100%;
}
img {
max-height:100%;
max-width:100%;
margin: auto;
}