Contain an image within a div?

后端 未结 7 818
北荒
北荒 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:30

      
    #container img {
            max-width:250px;
            max-height:250px;
            width: 250px;
            height: 250px;
            border:1px solid #000;
        }
    

    The img will lose aspect ratio

提交回复
热议问题