Contain an image within a div?

后端 未结 7 811
北荒
北荒 2020-12-13 00:08

I want to contain an image into a 250 x 250 div, forcing the image to resize but not stretch. How can I do this? By the way, the image will usually be bigger than the div it

7条回答
  •  爱一瞬间的悲伤
    2020-12-13 00:28

    You have to style the image like this

    #container img{width:100%;}
    

    and the container with hidden overflow:

    #container{width:250px; height:250px; overflow:hidden; border:1px solid #000;} 
    

提交回复
热议问题