Make image fill div completely without stretching

后端 未结 13 1724
情话喂你
情话喂你 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:52

    Taking out the line: max-width:100% in your CSS file seems to do the trick.

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

    Also you can add > to your closing div in your HTML file could make the code neater.

    Here is a working JSFiddle link: http://jsfiddle.net/HsE6H/19/

提交回复
热议问题