@Tatu Ulmanen是对的,这是浏览器默认问题。您不需要添加负边距,只需设置body/html标记的默认CSS属性即可。
为了安全起见,您应该使用CSS重置来消除浏览器样式默认值。以下是可以解决您问题的代码。在此之后,您可以将以下很好的CSS重置添加到所有CSS样式表的顶部。
html, body {
padding: 0;
margin: 0;
}
CSS重置:
/* 重置 */
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, font, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td
{ margin: 0; padding: 0; border: 0; outline: 0; font-weight: inherit; font-style: inherit; font-size: 100%; font-family: inherit; vertical-align: baseline; }
blockquote:before,
blockquote:after,
q:before, q:after { content: ""; }
blockquote, q { quotes: "" ""; }
body { line-height: 1; color: black; background: white; }
caption, th, td { text-align: left; font-weight: normal; }
:focus { outline: 0; }
table { border-collapse: separate; border-spacing: 0; }
ol, ul { list-style: none; }