full screen background html

后端 未结 5 699
情书的邮戳
情书的邮戳 2021-01-26 02:51

I\'m trying to show a picture as the background of my website so I\'m using the following code

HTML:

相关标签:
5条回答
  • 2021-01-26 03:07

    try this

    #bg {
    width: 100%;
    height: 100%%;
    background-size:100%;
    }
    
    0 讨论(0)
  • 2021-01-26 03:15

    I would use the following css:

    html { 
        background: url(images/bg.jpg) no-repeat center center fixed;
    
        -webkit-background-size: cover;
        -moz-background-size: cover;
        -o-background-size: cover;
        background-size: cover;
    }
    

    and remove your div entirely.

    To limit the size you can:

    #bg {
        min-height: 100%;
        max-width: 2000px;
        width: 100%;
        height: auto;
        position: fixed;
        top: 0;
        bottom: 0;
    }
    
    0 讨论(0)
  • 2021-01-26 03:26

    I haven't tested it, but add max-width:2000px; to your #bg selector.

    0 讨论(0)
  • 2021-01-26 03:27

    Just include max-width in your CSS.

     #bg {
        width: 100%;
        max-width: 2000px;
        height: 75%;
        position: absolute;
        z-index: -5000;
    }
    
    0 讨论(0)
  • 2021-01-26 03:29

    You can use max-width

    #bg {
        width: 100%;
        height: 75%;
        position: absolute;
        z-index: -5000;
    
        max-width: 2000px; /* use this to limit the maximum width */
    }
    
    0 讨论(0)
提交回复
热议问题