CSS: How can I get rid of the default window “padding”? An element set to 100% width doesn't reach the window's borders

前端 未结 4 641
孤城傲影
孤城傲影 2021-02-03 22:35

So I have an element that is placed directly inside body:


    
Some stuff...
Other stuff...
相关标签:
4条回答
  • 2021-02-03 22:52

    Add these to the style tag in body, like the following one:

    body { margin:0px; padding:0px; }
    

    It worked for me. Good luck!!

    0 讨论(0)
  • 2021-02-03 22:58

    An easy way to solve this problem is by getting rid of all the margins. And you can do that by the following code:

    * {
        margin:0;
    }
    

    This will solve the problem and will give you finer control over the margins of all elements.

    0 讨论(0)
  • 2021-02-03 23:11

    I found this problem continued even when setting the BODY MARGIN to zero.

    However it turns out there is an easy fix. All you need to do is give your HEADER tag a 1px border, aswell as setting the BODY MARGIN to zero, as shown below.

    body { margin:0px; }
    
    header { border:1px black solid; }
    

    Not sure why this works, but I use Chrome browser. Obviously you can also change the colour of the border to match your header colour.

    0 讨论(0)
  • 2021-02-03 23:17

    body has default margins on all browsers, so all you need to do is shave them off:

    body {
        margin: 0;
        text-align: center;
    }
    

    You can then remove the negative margins from #header.

    0 讨论(0)
提交回复
热议问题