"CSS 이미지 크기 비율에 맞게 줄이기"의 두 판 사이의 차이

잔글 (봇: 자동으로 텍스트 교체 (-</source> +</syntaxhighlight>, -<source +<syntaxhighlight ))
6번째 줄: 6번째 줄:
*너비·높이 둘 다 제한하면서 비율은 유지하고 싶은 경우
*너비·높이 둘 다 제한하면서 비율은 유지하고 싶은 경우
*너비·높이는 auto로 두고 max-width, max-height를 주어 크기 제한
*너비·높이는 auto로 두고 max-width, max-height를 주어 크기 제한
<source lang='html5' run outheight='150'>
<syntaxhighlight lang='html5' run outheight='150'>
<style>
<style>
.max-small {
.max-small {
16번째 줄: 16번째 줄:
   
   
<img class='max-small' src='https://upload.wikimedia.org/wikipedia/commons/thumb/5/50/Albert_Einstein_%28Nobel%29.png/260px-Albert_Einstein_%28Nobel%29.png'>
<img class='max-small' src='https://upload.wikimedia.org/wikipedia/commons/thumb/5/50/Albert_Einstein_%28Nobel%29.png/260px-Albert_Einstein_%28Nobel%29.png'>
</source>
</syntaxhighlight>


==방법 3: 너비·높이 중 둘 다 지정 #2==
==방법 3: 너비·높이 중 둘 다 지정 #2==
*배경이미지로 주고 <code>background-size: contain;</code>를 적용하는 방법
*배경이미지로 주고 <code>background-size: contain;</code>를 적용하는 방법
<source lang='html5' run outheight='150'>
<syntaxhighlight lang='html5' run outheight='150'>
<style>
<style>
.bg-small {
.bg-small {
30번째 줄: 30번째 줄:


<div class='bg-small'></div>
<div class='bg-small'></div>
</source>
</syntaxhighlight>


==같이 보기==
==같이 보기==

2021년 4월 13일 (화) 23:30 판

How to resize image proportionally with CSS
CSS 이미지 크기 비율에 맞게 줄이기
CSS 종횡비 유지한 채로 이미지 크기 조정

1 방법 2: 너비·높이 중 둘 다 지정 #1

  • 너비·높이 둘 다 제한하면서 비율은 유지하고 싶은 경우
  • 너비·높이는 auto로 두고 max-width, max-height를 주어 크기 제한
<style>
.max-small {
    width: auto; height: auto;
    max-width: 100px;
    max-height: 100px;
}
</style>
 
<img class='max-small' src='https://upload.wikimedia.org/wikipedia/commons/thumb/5/50/Albert_Einstein_%28Nobel%29.png/260px-Albert_Einstein_%28Nobel%29.png'>

2 방법 3: 너비·높이 중 둘 다 지정 #2

  • 배경이미지로 주고 background-size: contain;를 적용하는 방법
<style>
.bg-small {
    width: 100px; height: 100px;
    background: url('https://upload.wikimedia.org/wikipedia/commons/thumb/5/50/Albert_Einstein_%28Nobel%29.png/260px-Albert_Einstein_%28Nobel%29.png') no-repeat;
    background-size: contain;
}
</style>

<div class='bg-small'></div>

3 같이 보기

4 참고

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}