html css margin(white spaces at webpage edges)

你离开我真会死。 提交于 2021-02-08 08:38:38

问题


Basically I got problem with the edge of my website, it got this white spaces :

http://sadpanda.us/images/1885204-15X1WA4.jpg

While I want that web to look like this :

http://sadpanda.us/images/1885205-VG8KJ23.jpg

no white spaces.

Any idea where I've done wrong?


回答1:


That looks very much like the default margin on the <body>.

body {
  margin: 0;
}

Should solve it for you.


Quick Demo:

CSS:

html, body {
    height: 100%;
}
div {
    width: 100%;
    height: 100%;
    background: #ddd;
}

DEMO WITH SPACE

CSS:

html, body {
    height: 100%;
}
body {
    margin: 0; /* This will stop the margin, setting it to 0 */
}
div {
    width: 100%;
    height: 100%;
    background: #ddd;
}

DEMO WITHOUT SPACE




回答2:


each browser has some style for elements like body,h1...etc,that is called as user agent style sheet, they have some margin, if you want reset all css just use universal tag and put margin:0 ... like below..

*{ margin: 0;}


来源:https://stackoverflow.com/questions/21705517/html-css-marginwhite-spaces-at-webpage-edges

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