aspect css polyfill

作者: zengde 分类: 笔记 发布时间: 2021-05-29 07:09
.aspect-ratio-box {
  position: relative;
  max-width: 500px;
}
.aspect-ratio-box::before {
  float: left;
  padding-top: 56.25%;
  content: '';
}
.aspect-ratio-box::after {
  display: block;
  content: '';
  clear: both;
}
.aspect-ratio-box > img {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}