代码之家  ›  专栏  ›  技术社区  ›  Armeen Moon

维护不能创建垂直滚动条和不剪裁的纵横比框

  •  1
  • Armeen Moon  · 技术社区  · 6 年前

    问题: 如何确保我的视频保持纵横比(16x9),并且不会在非常小的高度视口上创建滚动条,也不会剪辑。

    重新创建:

    使用底部边缘使浏览器窗口非常宽和非常短,您将看到窗口现在有一个滚动条。

    .wrapper {
      background: green;
      height: 100%;
      width: 50%;
      margin: 0 auto;
      
    }
    .video {
      background: red;
      overflow: hidden;
      max-height: 0;
      padding-top: 56.25%;
    }
      <div class="wrapper">
        <div class="video">123</div>
      </div>
    1 回复  |  直到 6 年前
        1
  •  3
  •   Temani Afif    6 年前

    你可以考虑 max-width 你根据 vh 单位:

    .wrapper {
      background: green;
      height: 100%;
      width: 50%;
      margin: 0 auto;
      max-width: 160vh; 
      /* the 56.25% of this value should be less or equal to 100vh considering margin/padding/border
      
        In this case with 8px of body margin the max value should be:
         calc((100vh - 16px)*100/56.25)   
      */
    }
    
    .video {
      background: red;
      overflow: hidden;
      max-height: 0;
      padding-top: 56.25%;
    }
    <div class="wrapper">
      <div class="video">123</div>
    </div>