Stretch and scale a CSS image in the background - with CSS only

后端 未结 22 2545
迷失自我
迷失自我 2020-11-22 01:37

I want that my background image stretch and scale depending on the browser viewport size.

I\'ve seen some questions on Stack Overflow that do the job, like

22条回答
  •  深忆病人
    2020-11-22 01:42

    CSS3 has a nice little attribute called background-size:cover.

    This scales the image so that the background area is completely covered by the background image while maintaining the aspect ratio. The entire area will be covered. However, part of the image may not be visible if the width/height of the resized image is too great.

提交回复
热议问题