How to make iframe responsive using css | Sanwebcorner

How to make iframe responsive using css

In this post i will tell you how to make the iframe be responsive. Mostly we used the specified width and height for the iframe. Instead of this we should use the height and width in percentages so we will get the iframe also responsive. In this example i given how to create responsive iframe using simple css code. here i given the code and live demo check it out. I hope this post is very useful.







Code to Make Iframe Responsive using Css

<html>
<head>
<title>How to make Iframe Responsive</title>
<style>
html,body        {height:100%;}
.wrapper         {width:80%;height:100%;margin:0 auto;background:#CCC}
.h_iframe        {position:relative;}
.h_iframe .ratio {display:block;width:100%;height:auto;}
.h_iframe iframe {position:absolute;top:0;left:0;width:100%; height:100%;}
</style>
</head>
<body>
<div class="wrapper">
<div class="h_iframe">
<!-- a transparent image is preferable -->
<img class="ratio" src=""/>
<iframe src="http://www.sanwebcorner.com" frameborder="0" allowfullscreen></iframe>
</div>
<p>Please scale the "result" window to notice the effect.</p>
</div>
</body>
</html>