How to stretch the background image to fill a div

后端 未结 10 1147
慢半拍i
慢半拍i 2020-12-04 10:27

I want to set a background image to different divs, but my problems are:

  1. The size of image is fixed(60px).
  2. Varying div\'s size

How

10条回答
  •  天命终不由人
    2020-12-04 11:11

    To keep the aspect ratio, use background-size: 100% auto;

    div {
        background-image: url('image.jpg');
        background-size: 100% auto;
        width: 150px;
        height: 300px;
    }
    

提交回复
热议问题