//이미지 비율 유지하기 : S
//사용법:
// <div class="sustain_ratio_img" style="background-image:url(); --pc-width: 1920; --pc-height: 600;"></div>
.sustain_ratio_img {
display: block;
width: 100%;
height: 0;
padding-bottom: calc(100% * ( var(--pc-height) / var(--pc-width) ));
background-position: center center;
background-repeat: no-repeat;
background-size: cover;
text-indent: -9999px;
&.is_mobile {
padding-bottom: calc(100% * ( var(--mobile-height) / var(--mobile-width) ));
}
}
//이미지 비율 유지하기 : E
반응형으로 어느 가로폭에서든 처음 지정한 비율을 유지하고 싶을때 만들었습니다.
많이 활용해주세요~
기본 img 태그로도 만들 수 있지만
저는 백그라운드 이미지가 좋더라구요..
'프론트엔드 > HTML · CSS · Javascript' 카테고리의 다른 글
[CSS, JAVASCRIPT] onafterprint, onbeforeprint, 미디어쿼리 디바이스 분기를 이용한 프린트 퍼블리싱 (0) | 2022.03.25 |
---|---|
[css] flex, gap을 이용한 박스 리스트 grid 만들기 (0) | 2021.09.27 |
[css] 어떤 width 값에도 이미지 비율 유지하기 (0) | 2021.07.09 |
스크롤바 css (0) | 2021.03.15 |
메타태그 작성할때 팁 (0) | 2021.02.04 |