fixed background for part of a site (div) in iOS

后端 未结 1 514
忘掉有多难
忘掉有多难 2021-01-24 05:35

I want to have a fixed position background image that covers the whole screen only for a section of my website (actually two sections, but independently, so there is no

1条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-24 06:02

    I found this :

    .bg {
        background: url(image.jpg);
        background-size: cover;
        -webkit-background-size: cover;
        -moz-background-size: cover;
        -o-background-size: cover;
        height: 100%;
        width: 100%;
        position: fixed;
        background-position: center center;
        background-repeat: no-repeat;
    }
    

    here : https://css-tricks.com/forums/topic/full-page-backgrounds-on-ios-background-size-cover/page/3/

    basically you put your background in another div and give the fixed attribute to the div instead of the background. You need to add z-index:-1; and add white background or whatever to hide the picture where you don't want to see it.

    0 讨论(0)
提交回复
热议问题