Image auto resize to fit div container


How do you auto-resize a large image so that it will fit into a smaller width div container whilst maintaining it's width:height ratio?


Example: stackoverflow.com - when an image is inserted onto the editor panel and the image is too large to fit onto the page, the image is automatically resized.

share|improve this question
up vote175down voteaccepted

do not apply a width in the image tag. set your css to max-width:100%; max-height:100%;

Also, read this http://unstoppablerobotninja.com/entry/fluid-images

share|improve this answer
 
And what about height? –  Nicola Peluchetti May 11 '11 at 11:28
 
doing this should scale the width and height. however i do not know that much about scaling based on height. –  Thorn007 May 13 '11 at 20:31
10 
This will not scale both the height and width. –  Neil Jun 7 '11 at 3:40
2 
height: auto; if you want to specify a width only –  Roi Sep 10 '12 at 23:28
1 
What if the image is too small? –  Scott Rippey Jan 3 at 23:01



출처 - http://stackoverflow.com/questions/3029422/image-auto-resize-to-fit-div-container


'Development > CSS' 카테고리의 다른 글

css3 - transition  (1) 2014.04.27
css - 미디어쿼리(media query) @media  (0) 2013.11.19
css - 글자 자동 줄바꿈 word-break white-space  (0) 2013.10.12
CSS - 개발 생산성을 높이는 도구들  (0) 2013.09.16
css 수직 정렬  (0) 2012.12.24
Posted by linuxism
,