I need to resize an iframe to match its content, but the height properties I have tried don't account for elements with position: fixed
.
Assume a document with only two elements with the absolute
and fixed
classes.
body { padding: 0; margin: 0; }
.absolute {
position: absolute;
height: 100px;
}
.fixed {
position: fixed;
height: 200px;
}
html.scrollHeight
0 (viewport height in Opera/Firefox)html.offsetHeight
0body.scrollHeight
0 (viewport height in Chrome)body.offsetHeight
0body.outerHeight
0
If I add html { position: relative; }
, html.scrollHeight
will be 100px in Chrome, but no value will be 200px. At first I also had an issue with floats, but I solved that by adding a clearfix to body
.
I made a jsbin here: http://jsbin.com/ehixiq
If it's not possible to get the real height, what would be my best workaround? I only need to support the latest versions of Opera, Chrome and Firefox.