当您默认创建 HTML 页面时,<body>
以及其他一些元素,如段落标签 ( <p>
)、标题标签 ( <h1>
、<h2>
.. <h6>
) 等...具有默认padding
和margins
因此,您需要通过添加以下 css 来清除这些边距:
html, body, p, h1, h2, h3, h4, h5, h6 {
margin:0;
padding:0;
}
有关更多详细信息,请参阅CSS 重置
重置样式表的目标是减少浏览器在默认行高、页边距和标题字体大小等方面的不一致。
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, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed,
figure, figcaption, footer, header, hgroup,
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
font: inherit;
vertical-align: baseline;
}