본문 바로가기
Style Sheet/CSS

Aspect Ratio 이미지나 동영상을 비율대로 조정

by jimeal 2024. 4. 2.

참조

 

aspect-ratio | CSS-Tricks

The CSS property aspect-ratio lets you create boxes that maintain proportional dimensions where the height and width of a box are calculated automatically as

css-tricks.com

/* Keyword values */
aspect-ratio: auto; /* default */

/* Ratio values */
aspect-ratio: 1 / 1; /* width and height are equal proportion */
aspect-ratio: 2 / 1; /* width is twice the height*/
aspect-ratio: 1 / 2; /* width is half the height */
aspect-ratio: 16 / 9  /* typical video aspect ratio */
aspect-ratio: auto 4 / 3; /* width:height, unless it's a replaced element */
aspect-ratio: 0.5; /* float value */

/* Global values */
aspect-ratio: inherit;
aspect-ratio: initial;
aspect-ratio: unset;

주의 width, height 값이 같이 지정되어 있을 경우 적용이 되지 않는다