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

后端 未结 22 2236
迷失自我
迷失自我 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条回答
  •  闹比i
    闹比i (楼主)
    2020-11-22 02:00

    You can add this class into your CSS file.

    .stretch {
        background: url(images/bg.jpg) no-repeat center center fixed;
        -webkit-background-size: cover;
        -moz-background-size: cover;
        -o-background-size: cover;
        background-size: cover;
    }
    

    It works in:

    • Safari 3 or later
    • Chrome Whatever or later
    • Internet Explorer 9 or later
    • Opera 10 or later (Opera 9.5 supported background-size, but not the keywords)
    • Firefox 3.6 or later (Firefox 4 supports non-vendor prefixed version)

提交回复
热议问题