I have the following HTML:
<div class="container">
<div class="box">
<img src="https://placehold.co/600x400" class="image" />
<p>Some text</p>
<p>Some text</p>
<p>Some text</p>
<p>Some text</p>
</div>
</div>
And the following CSS:
body, p {
margin: 0;
}
.container {
height: 100vh;
background: skyblue;
}
.box {
height: 100%;
}
.image {
min-height: 0;
height: 100%;
}
CodePen link: https://codepen.io/robkom/pen/KKGgawv
If you reduce the size of the window, the image shrinks appropriately (down to 0
). This is expected. However, there is also text content inside of the box which appears outside the container!
I would like the text content (those p
tags) to "squeeze" the image down, so that everything fits inside the blue box. I also do not want the box to become smaller than the text content inside it. I thought setting min-height: min-content
(or max-content
) would do the truck but it doesn't.
How can I achieve the effect I'm after?
Clarification: I want the p
tags to basically determine the min-height of the container or box and the image to just take up the remaining space (if any) of the window. If the window is large enough then it should stretch (i.e. only the blue should be visible at all times).