【问题标题】:How can I give an iframe video different width and height on mobile & pc browsers?如何在移动和 PC 浏览器上为 iframe 视频提供不同的宽度和高度?
【发布时间】:2018-05-17 20:28:54
【问题描述】:

我的网站上有一个文本框,使文本更易于阅读。我的网站上有一个 iframe,放在移动设备上的盒子外面。所以我按照this 教程来解决这个问题。我试图让我的 iframe 视频在 pc 浏览器上更小,并在我的移动设备代码中缩小当前大小。现在pc上太大了有没有办法做到这一点?

HTML 代码:

<div class="video-container"><iframe src="https://www.youtube.com/embed/c0i88t0Kacs"></iframe>
</div>

CSS 代码:

.video-container {
position:relative;
padding-bottom:56.25%;
padding-top:30px;
height:0;
overflow:hidden; }

.video-container iframe, .video-container object, .video-container embed {
position:absolute;
top:0;
left:0;
width:100%;
height:100%; }

【问题讨论】:

标签: html css iframe mobile


【解决方案1】:

您可以为此任务使用引导程序或媒体查询, 在使用媒体查询时,您必须为您的设备提供适当的像素

引导

<div class="container">
 <div class="row">
   <div class="col-sm-12">
   </div>
  </div>
</div>

媒体查询

   @media screen and (max-width: 699px) and (min-width: 520px) {

  }

【讨论】:

    【解决方案2】:

    只需在您的 Css 中添加媒体查询

    平板电脑

    @media only screen and (max-width: 760px) {
    .video-container {//set you width and height}
    
    .video-container iframe, .video-container object, .video-container embed 
    {//set you width and height }
    }
    

    移动版

    @media only screen and (max-width: 480px) {
    .video-container {//set you width and height}
    .video-container iframe, .video-container object, .video-container embed 
    {//set you width and height }
    

    }

    【讨论】:

    • 如果我在“.video-container”上方添加“@media only screen and (max-width: 480px)”,我的屏幕会完全填满视频。我该如何解决?抱歉,我是 HTML/CSS 新手。
    • 你必须在css的末尾添加媒体查询。
    • 现在可以使用了!我忘记添加 .video-container 的宽度和高度。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多