Responsive css background images

前端 未结 19 1115
北荒
北荒 2020-11-22 05:39

I have a website (g-floors.eu) and I want to make the background (in css I have defined a bg-image for the content) also responsive. Unfortunately I really don\'t have any i

19条回答
  •  执笔经年
    2020-11-22 06:21

    If you want the same image to scale based on the size of the browser window:

    background-image:url('../images/bg.png');
    background-repeat:no-repeat;
    background-size:contain;
    background-position:center;
    

    Do not set width, height, or margins.

    EDIT: The previous line about not setting width, height or margin refers to OP's original question about scaling with the window size. In other use cases, you may want to set width/height/margins if necessary.

提交回复
热议问题