Full page background image with vertical scrolling

后端 未结 2 1551
旧巷少年郎
旧巷少年郎 2021-01-31 00:24

I\'m trying to create a page where the background image is responsive to your browser\'s screen size. However, I need content under that image such that if the person scrolls do

2条回答
  •  长发绾君心
    2021-01-31 01:15

    There is no need for position: absolute as tb11 suggests.

    You can simply set the height of the viewport using viewport units or by setting the height for the html, body, and image elements.

    Using vh - Demo and support chart:

    body { margin: 0; }
    .image {
        width:100vw;
        height: 100vh; 
        background: green;
        background-image: url('some-image.jpg');
        background-size: cover;
    }
    

    If you can't use vh, you'll have to set the height of the html and body elements as well so that you can use percents - Demo:

    html, body, .image { height: 100%; }
    body { margin: 0; }
    .image {
        width:100%;
        background: green;
        background-image: url('some-image.jpg');
        background-size: cover;
    }
    

提交回复
热议问题