【问题标题】:Element in iframe with height: 100% strechiframe 中的元素高度:100% 拉伸
【发布时间】:2015-08-22 18:55:29
【问题描述】:

我正在解决这个问题:

我有 iframe,我在其中展示网站,它有一些 html 结构。这个结构里面是元素,它有css属性:height: 100%; 问题是,该元素拉伸到 iframe 的全高,无论如何我认为不应该。你能给我一些想法,如何解决这个问题?

这是 iframe 内容的源代码:

<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>

这是源代码,我放了一个 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>

非常感谢您的帮助。

【问题讨论】:

    标签: html css iframe


    【解决方案1】:

    子页面(iframe 内的页面)将从左上角开始显示,因此通常不需要定位子页面。父页面上 iframe 尺寸的样式决定了将看到多少子页面。最简单有效的方法是让 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="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>
    

    【讨论】:

    • 我不确定,你完全知道,我需要做什么。 iframe 的大小还可以,问题是,iframe 内部是元素:.swiper-wrapper,其样式为:height: 100%;,问题是元素适合 iframe 大小 - 例如如果 iframe 的高度为 800 像素,则 .swiper-wrapper 的高度也为 800 像素。我需要防止这种行为。元素应该有 100% 的父母高度,而不是所有窗口....
    • 我知道,在这种情况下,使用相同的标记,但将 iframe 上的 height 属性和 height 属性更改为您想要的任何高度。 iframe(子页面)内的内容应该符合。如果您的内容被部分截断,请将overflow 更改为visible
    猜你喜欢
    • 2020-12-06
    • 2016-12-15
    • 2010-10-17
    • 1970-01-01
    • 1970-01-01
    • 2014-07-08
    • 2018-05-30
    • 2018-10-14
    • 2013-07-04
    相关资源
    最近更新 更多