How do I stretch a background image to cover the entire HTML element?

后端 未结 13 1184
难免孤独
难免孤独 2020-12-04 09:02

I\'m trying to get a background image of a HTML element (body, div, etc.) to stretch its entire width and height.

Not having much luck. Is it even possible or do I h

13条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-04 09:34

    If you need to stretch your background image while resizing the screen and you don't need compatibility with older browser versions this will do the work:

    body {
        background-image: url('../images/image.jpg');
        background-repeat: no-repeat;
        background-size: cover;
    }
    

提交回复
热议问题