【问题标题】:How to display a grid keeping 16:9 aspect ratio?如何显示保持 16:9 纵横比的网格?
【发布时间】:2020-01-03 02:06:11
【问题描述】:

我正在尝试显示实时摄像机网格。

我需要两个响应列保持项目的 16:9 纵横比。

我的代码是:

<div class="grid">

  <div class="item" *ngFor="let i of cameras">
    <iframe [src]="this.sanitizer.bypassSecurityTrustResourceUrl(i.url)"
            scrolling="no"
            frameBorder="0"
            allow="autoplay; encrypted-media">
            </iframe>
  </div>

</div>

还有 CSS

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  grid-template-rows: 1fr;
  grid-gap: 1px;

  .item {
    background: grey;
    display: flex;
  }

  .item:before {
    content: "";
    display: block;
    height: 0;
    width: 0;
    padding-bottom: calc(9/16 * 50%);
  }

  iframe{
    width:100%;
    height:100%;
    background:#F2F2F2;
    overflow:auto !important;
    -webkit-overflow-scrolling:touch !important;
  }
}

问题是如何保持 16:9 的纵横比。

你知道怎么做吗?

【问题讨论】:

标签: css ionic-framework sass flexbox css-grid


【解决方案1】:

CSS-Tricks 有一个很酷的技巧,它曾帮助我解决过类似的问题:

.videoWrapper {
  position: relative;
  padding-bottom: 56.25%; /* 16:9 */
  padding-top: 25px;
  height: 0;
}
.videoWrapper iframe {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}
<div class="videoWrapper">
  <iframe width="560" height="349" src="#" frameborder="0" allowfullscreen></iframe>
</div>

来源:https://css-tricks.com/NetMag/FluidWidthVideo/Article-FluidWidthVideo.php

【讨论】:

  • 尝试了这种方法并得到了与我原来的帖子类似的结果...padding-bottom 参数在框架下方创建了一个空白空间...
猜你喜欢
  • 2017-07-30
  • 2018-04-29
  • 1970-01-01
  • 2018-10-06
  • 1970-01-01
  • 1970-01-01
  • 2019-03-19
  • 2014-07-15
  • 1970-01-01
相关资源
最近更新 更多