【问题标题】:Fit an Absolute positioned html to an iframe使绝对定位的 html 适合 iframe
【发布时间】:2016-02-19 19:26:41
【问题描述】:

如何使绝对定位的 html 适合 iframe?我需要它来使其响应浏览器。我知道它应该使用媒体查询创建,但它是通过使用一些在线 html 工具使用绝对定位创建的。

所以我的计划是使用一个 iframe,它会根据浏览器的宽度和高度调整大小。然后里面的内容会根据 iframe 的大小进行缩放。

这个我已经试过了

<iframe width="1024" height="768" src="http://www.bbc.com" style="-webkit-transform:scale(0.5);-moz-transform-scale(0.5);"></iframe>

但是没有用。

iframe 中的 html 大小为 1920x1080。 iframe 的大小为 1600x900。我需要将 1920x1080 放入 1600x900 中,所以我需要缩小它。

【问题讨论】:

标签: css html iframe


【解决方案1】:

如果您不希望滚动条出现,iframe 的宽度/高度需要匹配其源宽度/高度设置,因此我将其更改为 1950px/1110(包括一些边距)。

如果滚动条仍然出现(内容比 iframe 大),您通常会使用 overflow: hidden,虽然它还没有完全跨浏览器,但将 scrolling=no 添加到 iframe 标记是。

.wrap { width: 480px; height: 270px; padding: 0; overflow: hidden; }
.frame {
  -ms-zoom: 0.25;
  -moz-transform: scale(0.25);
  -moz-transform-origin: 0 0;
  -o-transform: scale(0.25);
  -o-transform-origin: 0 0;
  -webkit-transform: scale(0.25);
  -webkit-transform-origin: 0 0;
}
.frame.nr1 { width: 1950px; height: 1110px; border: 1px solid black; }
.frame.nr2 { width: 1920px; height: 1080px; border: 1px solid black; }
<p>iframe with wider/higher settings</p>
<div class="wrap">
  <iframe class="frame nr1" src="https://www.htechcorp.net/sandbox/sample.html"></iframe>
</div>
<p>iframe using `scrolling=no`</p>
<div class="wrap">
  <iframe scrolling=no class="frame nr2" src="https://www.htechcorp.net/sandbox/sample.html"></iframe>
</div>

【讨论】:

  • 有点,但图像应该适合 iframe,它不应该滚动以查看图像的其他部分。
  • @Kiel 更新了,现在可以了。 iframe 设置为 1280,但 iframe 源是 1920,所以我将 iframe 更新为 1920
  • 关于 css 规模,是否有计算?因为我将动态设置包装器的宽度和高度。
  • @Kiel 你会在标记中动态设置宽度/高度吗?
  • 一旦用户调整窗口大小,它就会动态变化。
【解决方案2】:

这段代码让你的 iframe 负责

answer

iframe, object, embed {
        max-width: 100%;
}

【讨论】:

  • iframe 中的 html 大小为 1920x1080。 iframe 的大小为 1600x900。我需要将 1920x1080 放入 1600x900 中,所以我需要缩小它。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-30
  • 2016-05-15
  • 2015-05-09
  • 1970-01-01
  • 2015-10-27
相关资源
最近更新 更多