Make image fill div completely without stretching

后端 未结 13 1722
情话喂你
情话喂你 2020-11-30 04:22

I have large images of varying dimensions that need to completely fill 240px by 300px containers in both dimensions. Here is what I got right now, which only works for one d

13条回答
  •  执笔经年
    2020-11-30 04:49

    This could do the job:

    .container {
        float: left;
        height: 300px;
        width: 240px;
        background-color: red;
        margin: 20px;
    }
    
    img {
        width:240px;
        height:300px;
    }
    

提交回复
热议问题