【发布时间】:2014-04-22 17:32:04
【问题描述】:
我想设计一个包含 4 个iframes 的页面,并为其设计响应式布局。下面是在桌面上工作但在 ipad 上无法正常工作的代码。
我想要它的响应式布局。
【问题讨论】:
-
我需要为每个 iframe 包含标题。我可以在没有相对定位的情况下这样做吗?
标签: html css responsive-design
我想设计一个包含 4 个iframes 的页面,并为其设计响应式布局。下面是在桌面上工作但在 ipad 上无法正常工作的代码。
我想要它的响应式布局。
【问题讨论】:
标签: html css responsive-design
对于响应式布局,请使用 CSS 媒体查询
HTML
<div class="wrapper">
<div class="h_iframe">
<iframe src="//www.youtube.com/embed/9KunP3sZyI0" frameborder="0" allowfullscreen></iframe>
</div>
<div class="h_iframe">
<iframe src="//www.youtube.com/embed/9KunP3sZyI0" frameborder="0" allowfullscreen></iframe>
</div>
<div class="h_iframe">
<iframe src="//www.youtube.com/embed/9KunP3sZyI0" frameborder="0" allowfullscreen></iframe>
</div>
<div class="h_iframe">
<iframe src="//www.youtube.com/embed/9KunP3sZyI0" frameborder="0" allowfullscreen></iframe>
</div>
</div>
CSS
html, body {
height:100%;
}
.wrapper {
padding: 0 1%;
width:98%;
}
.h_iframe {
float:left;
margin:1% 2%;
width:46%;
}
iframe {
width:100%;
}
@media screen and (max-width: 768px) {
.wrapper {
margin:0 auto;
padding:0;
width:95%;
}
.h_iframe {
margin:0;
width:100%;
}
}
【讨论】:
这是页面上完整的响应式 4 iframe。
HTML
<div class="wrapper">
<div class="h_iframe1">
<iframe src="//www.youtube.com/embed/9KunP3sZyI0" frameborder="0" allowfullscreen></iframe>
</div>
</div>
<div class="wrapper">
<div class="h_iframe2">
<iframe src="//www.youtube.com/embed/9KunP3sZyI0" frameborder="0" allowfullscreen></iframe>
</div>
</div>
<div class="wrapper">
<div class="h_iframe3">
<iframe src="//www.youtube.com/embed/9KunP3sZyI0" frameborder="0" allowfullscreen></iframe>
</div>
</div>
<div class="wrapper">
<div class="h_iframe4">
<iframe src="//www.youtube.com/embed/9KunP3sZyI0" frameborder="0" allowfullscreen></iframe>
</div>
</div>
CSS
html, body {
height:100%;
}
.h_iframe1 iframe {
position:absolute;
top:0;
width:100%;
height:25%;
}
.h_iframe2 iframe {
position:absolute;
top: 25%;
width:100%;
height:25%;
}
.h_iframe3 iframe {
position:absolute;
bottom:25%;
width:100%;
height:25%;
}
.h_iframe4 iframe {
position:absolute;
bottom:0;
width:100%;
height:25%;
}
【讨论】:
基于Youtube iframe http://css-tricks.com/NetMag/FluidWidthVideo/Article-FluidWidthVideo.php的解释解决方案
【讨论】: