⭐️ 이미지 태그일 때
.parent {
position: relative;
width: 100%;
height: 0;
padding-top: calc(861 / 1280 * 100%);
}
img {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
height를 0을 주었기 때문에 박스 모델 높이에 영향을 주는 건 padding-top 뿐이다.
padding-top 계산식 => calc( 이미지 높이 / 이미지 폭 * 100%) 로 계산한다
이미 계산된 비율
aspect ratio | padding-top value
--------------|----------------------
16:9 | 56.25%
4:3 | 75%
3:2 | 66.66%
8:5 | 62.5%
⭐️ background 이미지 일 때
🍎 참고하기
https://stackoverflow.com/questions/1495407/maintain-the-aspect-ratio-of-a-div-with-css
Maintain the aspect ratio of a div with CSS
I want to create a div that can change its width/height as the window's width changes. Are there any CSS3 rules that would allow the height to change according to the width, while maintaining its ...
stackoverflow.com
https://www.w3schools.com/howto/howto_css_aspect_ratio.asp
How To - Aspect Ratio / Height Equal to Width
W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.
www.w3schools.com
반응형 웹에서 요소 리사이징하기
반응형 웹 디자인(responsive web design, RWD)이란 하나의 웹사이트에서 PC, 스마트폰, 태블릿 PC 등 접속하는 디스플레이의 종류에 따라 화면의 크기가 자동으로 변하도록 만든 웹페이지 접근 기법을
velog.io
반응형웹, CSS만으로 background-image 의 종횡비 유지하기
RWDB Responsive Web Design dB Web awards, 우수 하이브리드웹·반응형웹 모음 사이트
rwdb.kr
[CSS] 이미지 적용 및 crop 방법 A to Z
[CSS] 이미지 적용 및 crop 방법 A to Z 이번 포스팅에서는 CSS 로 이미지를 적용하는 방법과 Crop하는 방법에 대해 알아보겠습니다. 1. background-image 방식 CSS의 background 속성을 사용하여 DOM의 배경으로
nuhends.tistory.com
'Mark Up & StyleSheet > CSS & SCSS' 카테고리의 다른 글
[SCSS] Architecture (폴더 구조) (1) | 2023.12.11 |
---|---|
[CSS] filter 적용하기 (1) | 2023.12.10 |
[CSS] 헷갈리는 가상클래스 child vs of-type (2) | 2023.12.10 |
[CSS] CSS 명시도 계산법 (0) | 2023.11.04 |
[CSS] Reset CSS (1) | 2023.11.04 |