【发布时间】: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 的纵横比。
你知道怎么做吗?
【问题讨论】:
-
使用 flex 容器(带有 flex-direction 和 flex-wrap)并让项目保持它们的方面不是更容易吗? css-tricks.com/snippets/css/a-guide-to-flexbox
-
@MaximSaplin 我不熟悉 flexbox... 会检查这个,谢谢
标签: css ionic-framework sass flexbox css-grid