小编Jor*_*era的帖子

在保持比例的同时填充父 div

我希望有一个 div 部分,在保持比例的同时尽可能地填充其 div 父级。

渲染结果将是这样的:

在此处输入图片说明

到目前为止我所做的:

html,
body {
  height: 100%;
}

.parent {
  /* Parent's height and width are unknown,
     it could be dynamic, e.g. parent is part of a flex layout. */
  height: 80%;
  width: 90%;
  border-style: solid;
  border-width: 2px;
  border-color: black;
}

.child {
  width: 90vw;
  /* 90% of viewport vidth */
  height: 50.625vw;
  /* ratio = 9/16 * 90 = 50.625 */
  max-height: 90vh;
  max-width: 160vh;
  /* 16/9 * 90 = 160 */
  margin: auto; …
Run Code Online (Sandbox Code Playgroud)

css

6
推荐指数
1
解决办法
336
查看次数

标签 统计

css ×1