我在一个 wordpress 页面上有两个 iframe,我希望它根据屏幕分辨率使用 css 自行调整大小。我想出了如下代码:
<head>
<link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>">
<meta name=”viewport” content=”width=device-width, initial-scale=1.0″>
</head>
<nav>
<div id="menu-stream"><?php wp_nav_menu(array('menu' => 'cssmenu')); ?></div>
</nav>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div id="infos">
<?php
dynamic_sidebar('info');
dynamic_sidebar('date');
?>
</div>
<div id="rss">
dynamic_sidebar('rss');
</div>
<div class="entry">
<div class="Wrapper">
<iframe id="video" name="video_iframe" width="854" height="480" src="http://www.dailymotion.com/embed/video/xxxxx?autoPlay=1" frameborder="0"></iframe>
<iframe id="chat" name="chat_iframe" width="380" height="480" src="http://webchat.quakenet.org/?channels=xxxx..." frameborder="0"></iframe>
</div>
<?php the_content(); ?>
</div>
在 Chrome 或 Opera 上一切正常,但当我试用 Firefox 或 IE 时,iframe 没有出现。我可以听到 dailymotion 视频的声音,但它就是不显示。
这是CSS
.entry {
color: #c5c5c5;
font-family: Verdana, Arial, Sans-serif;
font-size: 14px;
text-align: justify;
margin-left: 10px;
margin-right: 12px;
margin-bottom: 20px;
border-bottom-left-radius: 8px;
border-bottom-right-radius: 5px;
background-color: #1e1e1e;
letter-spacing: -1px;
box-shadow:0px 0px 11px black;
}
.Wrapper {
padding-bottom: 56.25%;
padding-top: 25px;
height: 0;
}
.Wrapper iframe {
top: 0px;
left: 0px;
width: 100%;
height: 70%;
}
.Wrapper#chat {
width: 30%;
float: left;
}
.videoWrapper#video {
width: 70%;
float: left;
}
我还添加了一些媒体查询。我可以看到有问题:
.Wrapper iframe {
top: 0px;
left: 0px;
width: 100%;
height: 70%;
}
因为当我删除宽度和高度时它会显示,但当然不会再调整大小。谁能告诉我哪里出了问题?
这是我决定使用的调整大小解决方案的文章 http://css-tricks.com/NetMag/FluidWidthVideo/Article-FluidWidthVideo.php
最佳答案
这是更新的 Fiddle
你的问题是你的 div#entry
没有任何固定的宽度/高度,所以我添加了一些。
同样,position:relative
对您的框架很重要。
另一个考虑是我删除了 .Wrapper iframe
CSS,因为它由于覆盖了你的类 .Wrapper#video
和 .Wrapper#chat< 而无法存在
.
所以使用这个 CSS:
.entry {
color: #c5c5c5;
font-family: Verdana, Arial, Sans-serif;
font-size: 14px;
text-align: justify;
margin-left: 10px;
margin-right: 12px;
margin-bottom: 20px;
border-bottom-left-radius: 8px;
border-bottom-right-radius: 5px;
background-color: #1e1e1e;
letter-spacing: -1px;
box-shadow:0px 0px 11px black;
width: 1250px;
height: 500px;
}
.Wrapper {
padding-bottom: 56.25%;
padding-top: 25px;
height: 0;
}
.Wrapper#chat {
width: 30%;
float: left;
margin-right: 3px;
display: block;
}
.videoWrapper#video {
width: 70%;
float: left;
display: block;
position:relative;
}
您需要它是流畅的,然后将此 html 用于 iframe:
<div class="entry">
<div class="Wrapper">
<iframe id="video" name="video_iframe" width="79%" height="500px" src="http://www.dailymotion.com/embed/video/xxxxx?autoPlay=1" frameborder="0"></iframe>
<iframe id="chat" name="chat_iframe" width="20%" height="500px" src="http://webchat.quakenet.org/?channels=xxxx..." frameborder="0"></iframe>
</div>
</div>
请注意,我对框架使用了百分比宽度,并且减少了 1% 以避免填充问题。
关于html - 在 firefox/IE 上显示 iframe 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20335461/