CSS: Full Size background image

前端 未结 6 1346
失恋的感觉
失恋的感觉 2020-12-15 22:04

Trying to get full size background image with:

html {
    height: 100%;
    background:url(\'../img/bg.jpg\') no-repeat center center fixed;
    background-s         


        
6条回答
  •  自闭症患者
    2020-12-15 22:28

    You should use the body as the selector and not html, this will cause issues with your markup. Your code is below:

    html {
        height: 100%;
        background:url('../img/bg.jpg') no-repeat center center fixed;
        background-size: cover;
    }
    

    I would try something like:

    body {
        background:url('../img/bg.jpg') no-repeat 50% 0 fixed;
        margin: 0 auto;
    }
    

    You should not have to specify the dimensions for the image.

提交回复
热议问题