반응형일 때 가로의 길이가 변하면 세로의 길이도 비율에 맞게 변해야 자연스럽게 보인다.
하지만 반응형은 보통 가로의 길이와 세로의 길이가 같은 비율로 변하지 않기 때문에 퍼센트를 사용하면 결국 비율이 깨지게 된다.
<div class="parents">
<div class="child">
<img src="" alt="">
<span>hello</span>
</div>
</div>
먼저 비율을 유지할 부모 태그와 컨텐츠를 담을 자식태그를 만든다.
.parents {
position: relative;
width: 100%;
height: 0;
padding-bottom: 100%;
}
.child {
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
}