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

后端 未结 13 1171
难免孤独
难免孤独 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:38

    The following code I use mostly for achieving the asked effect:

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

提交回复
热议问题