JSFiddle - React, Tailwind, and code Playground
HTML
<!DOCTYPE html>
<!-- Onyr for StackOverflow -->
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<title>Responsive Iframe</title>
<link rel="stylesheet" type="text/css" href="./style.css">
</head>
<body id="page_body">
<h1>Responsive iframe</h1>
<div id="video_wrapper">
<iframe id="iframe" src="https://ipfs.kleros.io/ipfs/QmYs17mAJTaQwYeXNTb6n4idoQXmRcAjREeUdjJShNSeKh/index.html?%7B%22arbitrableContractAddress%22:%220xEbcf3bcA271B26ae4B162Ba560e243055Af0E679%22,%22arbitratorContractAddress%22:%220x988b3a538b618c7a603e1c11ab82cd16dbe28069%22,%22disputeID%22:%22183%22%7D"></iframe>
</div>
<p>
Presenting a solution for responsive iframe without aspect
ratio assumption.<br><br>
</p>
<script src="./main.js"></script>
</body>
</html>
CSS
html {
height: 100%;
max-height: 1000px;
}
body {
background-color: #44474a;
color: white;
margin: 0;
padding: 0;
}
#videoWrapper {
background-color: #333333;
position: relative;
padding-top: 25px;
padding-bottom: 100px;
height: 0;
margin: 10;
}
#iframe {
top: 0;
left: 0;
width: 100%;
height: 100%;
}
JavaScript
let videoWrapper = document.getElementById("video_wrapper");
let w;
let h;
let bodyWidth;
let bodyHeight;
// get window size and resize the iframe
function resizeIframeWrapper() {
w = window.innerWidth;
h = window.innerHeight;
videoWrapper.style["width"] = `${w}px`;
videoWrapper.style["height"] = `${h - 200}px`;
}
// call the resize function when windows is resized and after load
window.onload = resizeIframeWrapper;
window.onresize = resizeIframeWrapper;