Element in iframe with height: 100% strech

2019-09-12 08:35发布

I'm fighting with this problem:

I have iframe in which I'm showing website, which has some html structure. And inside this structure is element, which has css property: height: 100%; Problem is, that element stretch to iframes full height, anyway it shouldn't I think. Could you give me some idea, how to solve this problem?

Here is source code for iframe content:

<html>
    <head>
        <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css">
        <link rel="stylesheet" href="https://raw.githubusercontent.com/daneden/animate.css/master/animate.css" />
        <link rel="stylesheet" href="https://www.zeerat.com/assets/front/styles/swiper.css" />
        <link rel="stylesheet" href="https://www.zeerat.com/assets/front/styles/style.css" />
        <link rel="stylesheet" href="https://www.zeerat.com/assets/front/styles/grid.css" />
    </head>
    <body>
        <div id="overview">
            <div class="overview slider swiper-container swiper-container-horizontal">
                <div class="swiper-wrapper">
                    XXX
                </div>
            </div>
        </div>

        <div id="benefits">
            <div class="grid">
                <article id="article1" class="clearfix">
                    <div class="text col right">
                        <h2>People behavior in one picture</h2>
                    </div>
                </article>
            </div>
        </div>
    </body>
</html>

Here is source code, where I put an iframe:

<!DOCTYPE html>
<html lang="cs" dir="ltr">
  <head>
    <meta charset="UTF-8">
    <title>Titulek stránky</title>
  </head>
  <body>
    <iframe src="iframe.html" width="1600" height="4000"></iframe>
  </body>
</html>

Thank you very much for you help.

标签: html css iframe
1条回答
2楼-- · 2019-09-12 08:56

On the child page (the page inside the iframe) will be shown starting from the top left corner, so positioning the child page is usually not necessary. The styling of the iframe's dimensions on the parent page determines how much of the child page will be seen. The easiest and most effective way is to make the iframe responsive (able to adapt to changes of screen sizes and/or window)

<!DOCTYPE html>
<html lang="cs" dir="ltr">
  <head>
    <meta charset="UTF-8">
    <title>Titulek stránky</title>
  </head>
  <body>
    <iframe src="iframe.html" width="100%" height="100%" style="position: absolute; top:0; left:0; right:0; bottom: 0; width: 100%; height: 100%;overflow: hidden; overflow-x: hidden; overflow-y: hidden;" allowfullscreen webkitallowfullscreen mozallowfullscreen ></iframe>
  </body>
</html>
查看更多
登录 后发表回答