[CSS3] Use CSS Variables to Maintain the Aspect Ratio for an Element

section img {
  --aspect-ratio: calc( 4 / 3);
  --height: 30vmin;
  --width: calc(var(--height) * var(--aspect-ratio));
  height: var(--height);
  width: var(--width);
}

 

posted @ 2020-09-15 23:42  Zhentiw  阅读(128)  评论(0编辑  收藏  举报