Ich muss folgendes tun:
Kann jemand helfen?
Dinge, die ich nicht verwenden kann:
Position: Fest; (hauptsächlich aufgrund eines Skripts, das ich für die Seitenleisten verwendet habe.)
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Bus Management System</title>
<!-- Viewport meta tag to prevent iPhone from scaling our page -->
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script>
$(function(){
var iFrames = $('iframe');
function iResize() {
for (var i = 0, j = iFrames.length; i < j; i++) {
iFrames[i].style.height = iFrames[i].contentWindow.document.body.offsetHeight + 'px';}
}
if ($.browser.safari || $.browser.opera) {
iFrames.load(function(){
setTimeout(iResize, 0);
});
for (var i = 0, j = iFrames.length; i < j; i++) {
var iSource = iFrames[i].src;
iFrames[i].src = '';
iFrames[i].src = iSource;
}
} else {
iFrames.load(function() {
this.style.height = this.contentWindow.document.body.offsetHeight + 'px';
});
}
});
</script>
</head>
<style type="text/css" media="all">
html, body, iframe {width:100%; height:100%;box-sizing:border-box; margin:0; padding:0; border:0;}
body {border:4px solid green;}
iframe {border:6px solid red;width:100%; height:100%;display:block;}
#wrapper {border:2px solid blue; width:100%; height:100%;}
</style>
<body>
<div style="height:50px; background-color:#000; color:#fff;">Header</div>
<iframe src="http://www.google.com" style="width:100%; height:100%;" onLoad="calcHeight();"></iframe>
</body>
</html>
Nur-CSS-Lösung für 100% Breite und Höhe und reaktionsschnell
HTML
<div class="container">
<div class="h_iframe">
<iframe src="//www.youtube.com/embed/9KunP3sZyI0" frameborder="0" allowfullscreen></iframe>
</div>
</div>
CSS
html,body {
height:100%;
}
.h_iframe iframe {
position:absolute;
top:0;
left:0;
width:100%;
height:100%;
}
ohne Position: absolut
css
html,body {height:100%;}
.h_iframe iframe {width:100%; height:100%;}
.h_iframe {
height: 100%;
}
Und hier ist endlich der Riss
Moderne Browser unterstützen jetzt Folgendes:
width: calc(100% - 70px);
CSS
html,body {
height:100%;
margin-top:0;
margin-bottom:0;
}
.h_iframe iframe {
width:100%;
height:calc(100% - 75px);
}
.h_iframe {
height: 100%;
}
.element{
width:100%;
height:70px;
background:red;
}
HTML
<div class="container">
<div class="element">here it goes</div>
<div class="h_iframe">
<iframe src="//www.youtube.com/embed/9KunP3sZyI0" frameborder="0" allowfullscreen></iframe>
</div>
</div>
Einfach und sauber. jQuery ist erforderlich. Quelle: https://stackoverflow.com/a/3940802
Ein bisschen geändert
function iframeHeight() {
var newHeight = $(window).height();
var newWidth = $(window).width();
var buffer = 100; // space required for any other elements on the page
var newIframeHeight = newHeight - buffer;
$('iframe.fop').css('height',newIframeHeight).css('width',newWidth); //this will aply to all iframes on the page, so you may want to make your jquery selector more specific.
}
// When DOM ready
$(function() {
window.onresize = iframeHeight;
iframeHeight();
});
<iframe src="" target="_parent" width="100%" height="100%" class="fop"></iframe>
vw units funktionieren (getestet auf Chrome und Firefox)
iframe{
width:100vw;
}
Das hat bei mir funktioniert
<iframe frameborder="0" height="490" scrolling="no" src="" width="735"></iframe>
Normalerweise legen Sie Breite und Höhe für Iframes fest. Wenn der Inhalt größer ist, müssen Bildlaufleisten ausreichen. Das folgende Skript versucht dies zu beheben, indem der Iframe dynamisch an den geladenen Inhalt angepasst wird.
sie können diese Funktion verwenden, um die automatische Höhe mithilfe von jquery/javascript einzustellen
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script>
$(function(){
var iFrames = $('iframe');
function iResize() {
for (var i = 0, j = iFrames.length; i < j; i++) {
iFrames[i].style.height = iFrames[i].contentWindow.document.body.offsetHeight + 'px';}
}
if ($.browser.safari || $.browser.opera) {
iFrames.load(function(){
setTimeout(iResize, 0);
});
for (var i = 0, j = iFrames.length; i < j; i++) {
var iSource = iFrames[i].src;
iFrames[i].src = '';
iFrames[i].src = iSource;
}
} else {
iFrames.load(function() {
this.style.height = this.contentWindow.document.body.offsetHeight + 'px';
});
}
});
</script>
Und Ihre Iframe-HTML-Datei so
<iframe src="http://www.google.com" class="iframe" scrolling="no" frameborder="0"></iframe>