首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >子div的高度(包含iframe) -响应问题

问子div的高度(包含iframe) -响应问题
EN

Stack Overflow用户
提问于 2019-11-07 20:21:43
回答 1查看 27关注 0票数 0

我有非常简单的代码,我花了一天的时间来解决问题,但仍然没有进展:/我想用背景图像显示iframe。代码片段没有显示背景图像,所以你可以在这里看到现场演示:http://lukdan2.47.pl/index2.php

​

代码语言:javascript
复制
.parrent {
  width: 100%;
  background-image: url('http://lukdan2.47.pl/images/black-iphone-frame.png');
  background-position: top center;
  background-repeat: no-repeat;
  background-size: contain;
  position: relative;
  max-width: 427px;
}

.child {
  margin: 0 auto;
  position: relative;
  width: 73%;
  padding-top: 37%;
}

iframe {
  border: none;
  width: 100%;
  height: 100%;
  margin: 0;
}
代码语言:javascript
复制
<div class="parrent">
  <div class="child">
    <iframe src="http://sshtest.co.pl/" id="iphone-x-portrait"></iframe>
  </div>
</div>

​

正如你所看到的,iframe的高度太高了。我可以添加

​

代码语言:javascript
复制
.child {
    margin: 0 auto;
    position: relative;
    width: 73%;
    padding-top: 37%;
    height: 550px;
    padding-bottom: 37%;
}

​

它工作得很好。

但是,对于低于460px的屏幕,父div越来越小,因此子屏幕的静态高度不能正常工作。

我曾尝试更改父div以显示flex和table (也更改了子div ),但没有找到解决问题的方法。

请帮帮忙。

EN

回答 1

Stack Overflow用户

发布于 2019-11-08 17:20:34

好了,我已经找到解决方案了。

​

代码语言:javascript
复制
.iframe-container {
  padding-top: 56.25%;
  position: relative;
  background-image: url('http://lukdan2.47.pl/images/black-iphone-frame.png');
  background-position: top center;
  background-repeat: no-repeat;
  background-size: contain;
}

 
.iframe-container iframe {
border: 0;
height: 62%;
left: 40%;
position: absolute;
top: 0;
width: 20%;
margin: 0 auto;
padding-top: 11%;
padding-bottom: 0%;
}
代码语言:javascript
复制
<div class="iframe-container">
  <iframe src="http://sshtest.co.pl/"></iframe>
</div>

​

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58748689

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档