I want to simulate what a page will look like on another page, such as a web page preview on a little TV. I use an <iframe>
for this, and scale
in CSS to bring it down to a reasonable size.
<div class="tv">
<iframe src="https://example.com"></iframe>
</div>
.tv {
width: 960px;
height: 540px;
}
.tv iframe {
width: 1920px;
height: 1080px;
scale: 0.5;
transform-origin: 0 0;
margin: 0;
padding: 0;
}
Now, suppose the iframe size can be different, changed with script. If the iframe width/height become larger, the scale must become smaller. If the iframe width/height become smaller, the scale must become larger.
Is there a way to set the scale of an item so that it always fits within its container, preserving aspect ratio? Or must I calculate the scale in script, each time the size of the iframe changes?