We have this group project and I was assigned to make a certain iframe
resizable. I've been reading lots of forum posts since last week, and I found out that iframe
itself can't be resizable.
Is there a way to make my iframe
resizable?
The iframe HTML element is often used to insert contents from another source. Contents which needs resizing is done indirectly using a div tag. The trick is to initiate with a div tag and enclose within an iframe tag.
Edit the width attribute. You should see the attribute "width=" after the URL in the iframe tag. Edit the width in pixels in quotations (" ") after the "width=" attribute. For example, if you want the width to be 300 pixels, you would enter "width="300px"" after the URL in the tag.
Answer: Use the contentWindow Property You can use the JavaScript contentWindow property to make an iFrame automatically adjust its height according to the contents inside it, so that no vertical scrollbar will appear.
The best trick for responsive iframes, for now, is making an aspect ratio box. First you need a parent element with relative positioning. The iframe is the child element inside it, which you apply absolute positioning to in order to fill the area.
This can be done in pure CSS, like so:
iframe { height: 300px; width: 300px; resize: both; overflow: auto; }
Set the height and width to the minimum size you want, it only seems to grow, not shrink.
Live example: https://jsfiddle.net/xpeLja5t/
This technique has good support in all major browsers except IE.
These steps will make an iframe resizable:
Create a div for resizing. eg:
<div class="resizable"></div>
Apply the style tag for style of div.
.ui-resizable-helper { border: 1px dotted gray; } .resizable { display: block; width: 400px; height: 400px; padding: 30px; border: 2px solid gray; overflow: hidden; position: relative; } iframe { width: 100%; height: 100%; }
Include jQuery & jQuery UI
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/start/jquery-ui.css"rel="stylesheet" /> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script> <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
Execute Resizable
$(function () { $(".resizable").resizable({ animate: true, animateEasing: 'swing', animateDuration: 500 }); });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With