I have the following layout, made using flex.
.flexcontainer {
display: flex;
flex-direction: column;
}
.subcontainer1 {
display: flex;
flex-direction: row;
}
.subcontainer2 {
display: flex;
flex-direction: row;
}
.subcontainer1 .avatar {
flex: 1 0 5%;
}
.subcontainer1 .user {
flex: 1 0 80%;
}
.subcontainer1 .time {
flex: 1 0 10%;
}
.subcontainer2 .text {
flex: 2 0 0;
}
.subcontainer2 .media {
flex: 1 0 0;
}
.media img {
max-width: 100%;
max-height: 100%;
}
<div class="flexcontainer">
<div class="subcontainer1">
<div class="avatar">
<img src="https://i2.wp.com/oneword365.com/wp-content/uploads/oph-Avatar.png?resize=73%2C73"/>
</div>
<div class="user">
<div class="title">Sue Smith</div>
<div class="subtitle">PincoPallino</div>
</div>
<div class="time">
15th August 2017
</div>
</div>
<div class="subcontainer2">
<div class="text">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas vel porttitor risus. Integer dictum massa ac mollis posuere. Etiam dapibus odio euismod lacus tempus tempor. Donec sagittis eget purus non rhoncus. Ut ac est turpis. Ut et ornare felis. Vestibulum at facilisis sed.
</div>
<div class="media">
<img src="https://pbs.twimg.com/media/Doc_24PWsAAnx5w.jpg"/>
</div>
</div>
</div>
As you can see I set the image size to fit the div:
max-width: 100%;
max-height: 100%;
But doing this makes it so that the div containing the image grows off screen instead of stopping in the "above the fold" section of my page (in other words what the users see in the first screen).
If you run the snippet or open my CodePen link, you can see in both cases that the image fits inside the div, but the div doesn't fit in the above the fold section.
I would like to have the div to not go below the screen and the image to have the size of the div rather than the other way around.
Since the image is dinamically loaded, is it possible to do this using HTML and CSS?