Resize a div element to its background image size

前端 未结 6 608
忘了有多久
忘了有多久 2021-01-04 11:24

Is it possible to make a

adapt to its background image? I mean to maintain the proportions width and height.

Clarification:

6条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-04 12:07

    Yes. We can make background image adapt to its div, like make it responsive too.

    Tips for a responsive background image: background-size:cover
    -set bg image to background-size cover
    -in css the padding set to percentage both top and bottom
    -make the bg image no repeat

    see this link: https://jsfiddle.net/beljems/dtxLjmdv/

提交回复
热议问题