Make image fill div completely without stretching

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

    Background can do this

    1. set image as background

    2.

    div {
       -webkit-background-size: auto 100%;
       -moz-background-size: auto 100%;
       -o-background-size: auto 100%;
       background-size: auto 100%;
    }
    

    or

    div {
      -webkit-background-size: cover;
      -moz-background-size: cover;
      -o-background-size: cover;
      background-size: cover;
    }
    

提交回复
热议问题