我有非常简单的代码,我花了一天的时间来解决问题,但仍然没有进展:/我想用背景图像显示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%;
}
它工作得很好。
但是,对于低于460px的屏幕,父div越来越小,因此子屏幕的静态高度不能正常工作。
我曾尝试更改父div以显示flex和table (也更改了子div ),但没有找到解决问题的方法。
请帮帮忙。
发布于 2019-11-08 17:20:34
好了,我已经找到解决方案了。
.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://stackoverflow.com/questions/58748689
复制相似问题