I want to design a web page with a banner and an iframe. I hope the iframe can fill all the remaining page height and be resized automatically as the browser is resizing. Is it possible to get it done without writing Javascript code, only with CSS?
I tried set height:100%
on iframe, the result is quite close but the iframe tried to fill the whole page height, including the 30px
height of banner div element, so I got unneccessary vertical scrollbar. It's not perfect.
Update Notes: Excuse me for not describing the question well, I tried CSS margin, padding attribute on DIV to occupy the whole remining height of a web page successfully, but the trick didn't work on iframe.
<body>
<div style="width:100%; height:30px; background-color:#cccccc;">Banner</div>
<iframe src="http: //www.google.com.tw" style="width:100%; height:100%;"></iframe>
</body>
Any idea is appreciated.
It will work with below mentioned code
Why not do this (with minor adjustment for body padding/margins)
try the following:
it worked for me
If you have access to the content of the iframe that will be loaded, you can tell its parent to resize whenever it resizes..
If you have more than one iframe on the page, you may need to use id's or other clever methods to enhance .find("iframe") so that you're selecting the correct one.
We use a JavaScript to solve this problem; here is the source.
Note:
ifm
is the iframe IDpageY()
was created by John Resig (the author of jQuery)MichAdel code works for me but I made some minor modification to get it work properly.