My element is not filling the entire space of the page

前端 未结 3 1933
死守一世寂寞
死守一世寂寞 2021-01-26 14:12

So using the CSS code below I wanted to make my page fill entirely with an image located on my computer. Instead, it turned out like this:

#background {
    back         


        
相关标签:
3条回答
  • 2021-01-26 14:41

    All browsers come with a default style sheet. It provides a basic set of CSS rules.

    Here is a sample default style sheet from the W3C: https://www.w3.org/TR/CSS22/sample.html

    As you can see from the sample, it is recommended that browsers include body { margin: 8px }. That's likely the source of the white space between the body and the viewport.

    To override the default use body { margin: 0; }.

    0 讨论(0)
  • 2021-01-26 14:52
    html, body {
        margin: 0px;
        padding: 0px;
    }
    
    0 讨论(0)
  • 2021-01-26 15:03

    Try this. Does it work

    body {margin: 0;}
    

    EDITED: For updated problem

    #background {
        background: url(images/bg.jpg) no-repeat center center fixed;
        background-size: cover;
    }
    
    0 讨论(0)
提交回复
热议问题