• 회원가입
  • 로그인
  • 구글아이디로 로그인

[image] CSS - object-fit 속성 - 컨테이너에 맞게 '이미지/비디오' 크기 조정 방법 지정 (= object-fit속성 = 어브젝트핏속성) ※ img/video 사이즈 조정

목차

  1. object-fit 예제 - 각 속성값별 효과 차이 확인
  2. object-fit 정의
  3. object-fit 구문
  4. object-fit 예제 - 각 이미지를 완전 둥글게 만들기

 

object-fit 예제 - 각 속성값별 효과 차이 확인

 

<style>

img.a {width: 100px; height: 200px; object-fit: fill; border:1px solid red;}

img.b {width: 100px; height: 200px; object-fit: contain; border:1px solid red;}

img.c {width: 100px; height: 200px; object-fit: cover; border:1px solid red;}

img.d {width: 100px; height: 200px; object-fit: none; border:1px solid red;}

img.e {width: 100px; height: 200px; object-fit: scale-down; border:1px solid red;}

</style>


<table>

    <tr>

        <th>원본</th>

        <th>fill</th>

        <th>contain</th>

        <th>cover</th>

        <th>none</th>

        <th>scale-down</th>

    </tr>

    <tr>

        <td><img src="https://picsum.photos/200/150" alt="원본"></td>

        <td><img class="a" src="https://picsum.photos/200/150" alt="fill"></td>

        <td><img class="b" src="https://picsum.photos/200/150" alt="contain"></td>

        <td><img class="c" src="https://picsum.photos/200/150" alt="cover"></td>

        <td><img class="d" src="https://picsum.photos/200/150" alt="none"></td>

        <td><img class="e" src="https://picsum.photos/200/150" alt="scale-down"></td>

    </tr>

</table>

 

결과보기

 

object-fit 정의

 

컨테이너에 맞게 '<img>/<video>' 크기 조정 방법 지정.

 


 

1. cf

 

2.

  • 기본값: fill
  • 상속여부: X
  • 애니효과: X
  • CSS버전: CSS3
  • JS구문: object.style.objectFit="cover"

 

3.

IE 제외한 주요 최신 브라우저 모두 지원.

 

4. MDN object-fit 예제보기

https://developer.mozilla.org/en-US/docs/Web/CSS/object-fit

 

 

object-fit 구문

 

selector {object-fit: fill|contain|cover|none|scale-down|initial|inherit;}

 


[속성값]

 

  • fill - 전체 화면을 늘리거나 눌러 상자를 채움.
  • contain - 원본 이미지의 '가로/세로' 비율 유지한 채 줄어듦.
  • cover ★ - 상자를 다 채울만큼 '가로/세로' 비율 유지한 채 키운 후, 양쪽을 자름.
  • none - 원래 크기 유지한 채, 양쪽을 자름.
  • scale-down - none과 contain 중 크기가 더 작은 값 자동 선택.
  • initial - 이 속성의 기본값 선택.
  • inherit - 부모요소의 속성값 상속.

 

 

object-fit 예제 - 각 이미지를 완전 둥글게 만들기

 

<style>

#box img {

    width: 200px; 

    height: 200px; 

    border-radius: 50%;

    object-fit: cover;

}
</style>

 

<div id="box">

    <img src="https://picsum.photos/200/300" alt="이미지 1">

    <img src="https://picsum.photos/200/300" alt="이미지 2">

    <img src="https://picsum.photos/200/300" alt="이미지 3">

</div>

 

결과보기

 


분류 제목
outline CSS - outline-color 속성 - 외곽선두께 (= 아웃라인컬러속성 = outline-color속성…
box CSS - width 속성 ★ - 너비 (= 가로길이 = width속성 = 위드스속성, 상속X)
box CSS - height 속성 ★ - 높이 (= 세로길이 = height속성 = 하이트속성) (※ vh, vw…
box CSS - min-width 속성 - 최소너비 (=최소가로길이 = min-width속성 = 민위드스속성)
box CSS - min-height 속성 - 최소높이 (= 최소세로길이 = min-height속성 = 민하이트속성…
box CSS - max-width 속성 - 최대너비 (= 최대가로길이 = max-width속성 = 맥스위드스속성)
box CSS - max-height 속성 - 최대높이 (= 최대세로길이 = max-height속성 = 맥스하이트속…
font CSS - font 속성 ★ - 글자스타일종합 (= font속성 = 글씨체 = 서체 = 글꼴 = 폰트속성, …
font CSS - font-size 속성 ★ - 글자크기 (= 글씨체크기= 글씨크기 = 서체크기= 글씨크기 = …
font CSS - font-family 속성 ★ - 글자종류 (= font-family속성 = 폰트패밀리속성 = 글…
font CSS - font-weight 속성 ★ - 글자굵기 (= font-weight속성 = 폰트굵기 = 글씨체굵…
font CSS - font-style 속성 - 글자기울기 (= 이텔릭체 여부 = 이탤릭 글씨체 = 글자 기울려쓰기 … 1
font CSS - font-variant 속성 - 작은 대문자 (= font-variant속성 = 폰트베리언트 = …
text CSS - color 속성 ★ - 글자색깔 (=글자색상=글자색깔=글자컬러 = 텍스트색깔 = 컬러속성 = co…
text CSS - direction 속성 - 텍스트방향 (= 텍스트진행방향 = direction속성 = 디렉션속성)…
text CSS - letter-spacing 속성 ★ - 글자 간격 사이사이 띄우기 ( 텍스트사이띄우기 = 문자 간…
text CSS - line-height 속성 ★ - 텍스트라인높이 (= line-height속성 = 텍스트줄높이 =…
text CSS - text-align 속성 ★ - 텍스트정렬 (= text-align속성 = 텍스트얼라인속성)
text CSS - text-decoration 속성 ★ - 텍스트라인 꾸미기 (= 밑줄/밑선, 가운데줄/취소선, 윗…
text CSS - text-indent 속성 ★★ - 단락 첫줄 텍스트 들여쓰기 (= text-indent속성 = …
4/25
목록
찾아주셔서 감사합니다. Since 2012