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

强颜欢笑 提交于 2019-11-30 06:27:33

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.

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.

Tharindulucky

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

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

It worked for me. Good luck!!

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!