html - 自适应iframe仅适用于Youtube,不适用于Vimeo

标签 html css responsive-design youtube vimeo-player

编辑:按建议插入摘录。

经过无数的帖子和教程之后:我已经设法获得以下代码来完成我所需的工作,但仅限于YouTube嵌入式视频:

#container {

      width: 100%;
      height: 1px;
      position: relative;
    }
    #navi,
    #infoi {
      width: 60%;
      height: 60%;
      position: absolute;
      top: 0;
      left: 0;
      z-index: 10;
    }
        #closeB {
            position: fixed;
            top: 28%;
            left: 79%;
            width: 30px;
            height: 30px;
            border: 0;
            cursor: hand;
            cursor: pointer;
            background-color: grey;
        }
        video-responsive {
        position: relative;
        overflow: hidden;
        padding-top: 56.25%;
            padding-top: 60px;
    }
        .video-responsive iframe {
        position: fixed;
        top: 30%;
        left: 20%;
        width: 60%;
        height: 60%;
        border: 0;
    box-shadow: 6px 6px 5px 0px rgba(0,0,0,0.75);
    }
    <div id="container">
    
                  <div id="infoi">
                        <div class="video-responsive">
        <iframe src="https://www.youtube.com/embed/dQw4w9WgXcQ" gesture="media"  allow="encrypted-media" allowfullscreen></iframe>
    </div>                      
                      <button id="closeB">X</button>
    
          </div>
    </div>


这段代码可以满足我对YouTube视频的要求:
  • 将视频 float 在其他所有内容之上
  • 在中间
  • 在所有屏幕尺寸下都响应
  • 关闭按钮位于视频的左上角(在
    它)在我尝试的每个窗口中调整大小。

  • 但是,一旦我将视频源更改为Vimeo(<iframe src="https://player.vimeo.com/video/148751763")
    它不再起作用(关闭按钮从iframe到处徘徊,它不会像嵌入youtube一样一直停留在角落)

    片段2:

    #container {
    
          width: 100%;
          height: 1px;
          position: relative;
        }
        #navi,
        #infoi {
          width: 60%;
          height: 60%;
          position: absolute;
          top: 0;
          left: 0;
          z-index: 10;
        }
            #closeB {
                position: fixed;
                top: 28%;
                left: 79%;
                width: 30px;
                height: 30px;
                border: 0;
                cursor: hand;
                cursor: pointer;
                background-color: grey;
            }
            video-responsive {
            position: relative;
            overflow: hidden;
            padding-top: 56.25%;
                padding-top: 60px;
        }
            .video-responsive iframe {
            position: fixed;
            top: 30%;
            left: 20%;
            width: 60%;
            height: 60%;
            border: 0;
        box-shadow: 6px 6px 5px 0px rgba(0,0,0,0.75);
        }
    <div id="container">
        
                      <div id="infoi">
                            <div class="video-responsive">
            <iframe src="https://player.vimeo.com/video/148751763" gesture="media"  allow="encrypted-media" allowfullscreen></iframe>
        </div>                      
                          <button id="closeB">X</button>
        
              </div>
        </div>

    最佳答案

    你在说这个吗

    https://codepen.io/Rishab2019/pen/NWGgYBX

      <div id="container">
    
      <div id="infoi">
         <div class="video-responsive">
       <iframe src="https://player.vimeo.com/video/148751763" gesture="media" 
      allow="encrypted-media" allowfullscreen></iframe>
    
      </div>                      
      <button id="closeB">X</button>
    
          </div>
      </div>
    

    的CSS
      #container {
    
      width: auto!important;
      height: auto;
      position: relative;
    
    }
    #navi,
    #infoi {
      width: auto;
      height: auto;
      position: absolute;
      top: 0;
      left: 0;
      z-index: 10;
        }
      #closeB {
       position: fixed;
    
       left:61.3%;
       width: 30px;
       height: 30px;
       border: 0;
       cursor: hand;
       cursor: pointer;
       background-color: grey;
        }
       .video-responsive {
        position: relative;
        width: auto;
        height: auto;
    
    
       }
        iframe {
        position: fixed;
        width: 100%;
        height: 100%;
        border: 0;
        box-shadow: 6px 6px 5px 0px rgba(0,0,0,0.75);
       }
    

    关于html - 自适应iframe仅适用于Youtube,不适用于Vimeo,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61465364/

    相关文章:

    html - 如何在三 Angular 形内制作边框?

    html - 通过将鼠标悬停在段落上使部分可见

    html - Bootstrap Jumbotron 不会变成整个 body 宽度

    css - 将文件夹中的所有 CSS 文件添加到 nuxt.config

    html - 将网站调整为移动设备时禁用垂直边框

    css - 为什么重定向和 A 记录会导致同一设备上的不同媒体查询

    html - 用百分比调整内容的高度

    jquery - 更改 Bootstrap 的 Accordion

    javascript - Amcharts 气球框将时间值显示为 "24:05"而不是 "00:05"

    jquery - 接受 =“image/*” 和 jQuery 验证