How to use 100% CSS background-image with scrolling content?

前端 未结 3 1914
感情败类
感情败类 2021-01-04 09:53

I want to create a site with a background image that always fills the entire window, even if the content can scroll vertically.

I have created this JSFiddle using ba

3条回答
  •  再見小時候
    2021-01-04 10:24

    Use background-attachment: fixed;

    Demo

    html { 
        height: 100%;
        margin:0px;
        background: url(http://www.freegreatpicture.com/files/147/18380-hd-color-background-wallpaper.jpg) no-repeat center center;
        background-size: cover;
        background-attachment: fixed;
    }
    

    Also, I didn't got why you are using position: absolute; on the wrapper element, generally you should be using position: relative;

提交回复
热议问题