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

我的代码非常简单,我花了一天的时间解决问题,但仍然没有进展:/我想用背景图像显示iframe。代码段代码未显示背景图片,因此您可以在此处观看实时演示:http://lukdan2.47.pl/index2.php

.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;
}
<div class="parrent">
  <div class="child">
    <iframe src="http://sshtest.co.pl/" id="iphone-x-portrait"></iframe>
  </div>
</div>

您可以看到iframe的高度过高。我可以添加

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

它工作正常。

但是,对于低于460像素的屏幕,父div会变小,因此子级的静态高度无法正常工作。

我尝试将父div更改为显示flex和table(还更改了子div),但没有发现能解决我的问题的方法。

请帮助。

zkx993299184 回答:子div的高度(包含iframe)-响应性问题

好的,我找到了解决方案。

.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%;
}
 
<div class="iframe-container">
  <iframe src="http://sshtest.co.pl/"></iframe>
</div>

本文链接:https://www.f2er.com/3144917.html

大家都在问