@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; }