scroll div over another div

前端 未结 5 2108
长发绾君心
长发绾君心 2021-02-04 15:42

I have two div with a height of 100%. And when you scroll, I want that the second div over the other scrolls, without scrolling the first up.

Like on this site: http://w

5条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-04 16:34

    There is a much simpler way. I found it on W3Schools. The important part is to add background-attachment: fixed. The full CSS looks like this:

    .banner {
        background-image: url("foo.jpg");
        min-height: 500px; 
        background-attachment: fixed;
        background-position: center;
        background-repeat: no-repeat;
        background-size: cover;
    }
    

提交回复
热议问题