I have a static height container.
Inside I have one div
element with an img
element inside.
Below that there is a p
tag which is populated dynamically with text.
When the text is longer and the p
tag becomes larger I want the image above to shrink to make room inside the container.
I have been trying to do this with flex
and flex-shrink
. This is what I've got:
http://codepen.io/niper1/pen/yaBxvx
#main {
width: 100px;
height: 200px;
border: 1px solid #c3c3c3;
display: -webkit-flex; /* Safari */
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
#main div {
flex-shrink: 3;
}
img {
height: 100%;
width: auto;
max-width: 100%;
}
p {
flex-shrink: 0;
}
<div id="main">
<div style="background-color:lightblue;">
<img src="http://fakeimg.pl/250x100/">
</div>
<p>Test text Test text Test text Test text Test text Test text Test text Test text Test text Test text Test text Test text Test text Test text Test text N</p>
</div>
As you can see, the img
tag is not shrinking to make enough space. Is this possible to do with flex-box or am I going to have to look for a different route?