CSS: How to force background image to stretch/compress to fit div, without keeping aspect ratio

后端 未结 3 1473
梦毁少年i
梦毁少年i 2021-01-21 01:43

I\'m having a frustrating issue, and would love some help.

I\'ve written a script to allow me to resize a div on screen for an application I\'m building for a client, b

3条回答
  •  春和景丽
    2021-01-21 02:17

    In CSS, the background-size property can transform the way the background image proportions itself to the element.

    background-size: cover
    

    Edit:

    If you want to keep the structure, you can use CSS object-fit properties https://developer.mozilla.org/en-US/docs/Web/CSS/object-fit

提交回复
热议问题