In order to ensure that both images and iframes within a fixed height container are responsive and do not overflow vertically or horizontally, you can apply the following CSS:
img {
max-width: 100%;
max-height: 100%;
}
This CSS rule will prevent portrait images from overflowing vertically and landscape images from overflowing horizontally.
For iframes, one common technique is using the "padding-ratio" method, where the padding of the wrapper element is set to the aspect ratio of the iframe (e.g. 56.25% for a 16:9 video):
.iframe-wrapper {
position: relative;
height: 0;
padding-top: 56.25%;
overflow: hidden;
}
.iframe-wrapper iframe {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
However, while this approach allows the iframe to scale with the width of the viewport, it does not adjust properly when the height of the viewport changes. The goal is to have the iframe behave similarly to how the images respond to different screen sizes.