프레임 레이아웃

Frame layout

이미지·영상처럼 원본 비율이 제각각인 콘텐츠를 정해진 종횡비 틀에 가둬 자르는 레이아웃. `aspect-ratio` + `object-fit: cover`가 핵심입니다.

다른 이름: Every Layout Frame
···
html
<div class="frame-box" id="fb">
  <div class="art"></div>
  <span class="badge" id="badge">16 / 9</span>
</div>
css
.frame-box{position:relative;width:min(72%,260px);aspect-ratio:16/9;border-radius:12px;overflow:hidden;
  border:1px solid var(--line);transition:aspect-ratio .9s cubic-bezier(.4,0,.2,1);background:var(--surface)}
.art{position:absolute;top:50%;left:50%;width:260px;height:260px;transform:translate(-50%,-50%);
  background:
    radial-gradient(circle at 50% 50%,transparent 0,transparent 30px,var(--accent) 31px,var(--accent) 46px,transparent 47px,transparent 70px,var(--accent-3) 71px,var(--accent-3) 84px,transparent 85px),
    conic-gradient(from 0deg,var(--accent-2),var(--accent),var(--accent-3),var(--accent-2))}
.badge{position:absolute;right:6px;bottom:6px;font:700 10px/1 ui-monospace,monospace;background:rgba(0,0,0,.55);
  color:#fff;padding:3px 7px;border-radius:4px}
js
const fb = document.getElementById('fb');
const badge = document.getElementById('badge');
const ratios = [
  ['16 / 9', '16 / 9'],
  ['1 / 1', '1 / 1'],
  ['3 / 4', '3 / 4'],
  ['21 / 9', '21 / 9'],
];
let i = 0;
setInterval(() => {
  const r = ratios[i % ratios.length];
  fb.style.aspectRatio = r[0];
  badge.textContent = r[1];
  i++;
}, 1900);

`aspect-ratio: 16 / 9`를 컨테이너에 주면 폭만 정해도 높이가 비율에 맞춰 자동 계산됩니다. 문제는 그 안에 들어가는 이미지·영상의 원본 비율이 프레임과 다를 때입니다 — 그냥 늘리면(`width: 100%; height: 100%`) 찌그러지고, 원본 비율을 지키면(`object-fit: contain`) 프레임에 여백이 남습니다.

`object-fit: cover`는 셋 중 가장 흔히 쓰이는 답입니다. 원본 비율은 지키되 프레임을 빈틈없이 채우도록 확대하고, 넘치는 부분은 `overflow: hidden`처럼 잘라냅니다. `object-position`으로 "어느 부분을 남길지"(인물 사진이면 보통 top이나 50% 30%처럼 얼굴 쪽)를 조절합니다. `<img>`·`<video>`가 아니라 일반 `<div>` 배경이라면 `background-size: cover`가 같은 역할을 합니다.

프레임 자체의 비율을 바꿔도(정사각형 썸네일 ↔ 와이드 배너) 안의 콘텐츠는 코드를 건드릴 필요가 없습니다 — `object-fit: cover`가 매번 알아서 다시 잘라주기 때문입니다. 그리드에 섞인 여러 이미지의 크기가 제각각이어도 이 프레임을 씌우면 시각적으로 가지런한 격자가 됩니다.

언제 쓰나

사용자 업로드 이미지, 다양한 원본 비율의 영상 썸네일처럼 "원본 크기를 통제할 수 없는" 콘텐츠를 격자·카드에 가지런히 넣을 때 필수입니다.