固定宽高比

88 阅读1分钟

固定宽高比

paddingTop 实现

<style>
  .wrapper {
    width: 400px;
  }
  .box {
    padding-top: 50%;
  }
</style>
<div class="wrapper">
  <div class="box"></div>
</div>

aspect-ratio

<style>
  .box {
    width: 400px;
    aspect-ratio: 2;
  }
</style>