总览
1.我们的浏览器会添加默认样式,可能会影响到我们正常的设置
2.通常情况下,我们在编写网页的时候会去除浏览器的默认样式
3.
一、理解默认外边距的存在
1.这是我们未设置 外边距的 body,浏览器却显示为 8px 的外边距
2.这是我们未设置 外边距的 p 元素,但是浏览器却显示外边距为 16px
3.我们并未设置p元素的外边距,实际显示的效果却是这样:
二、如何去除浏览器默认样式(去除默认外边距)
1.在css文件中,添加如下代码:(这种方法清除得不是很干净)
*{
margin: 0px;
padding: 0px;
}
2.引入css reset文件,让它帮我们清除所有的样式(这种方法清除得很干净)
/* http://meyerweb.com/eric/tools/css/reset/
v2.0 | 20110126
License: none (public domain)
*/
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;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure,
footer, header, hgroup, menu, nav, section {
display: block;
}
body {
line-height: 1;
}
ol, ul {
list-style: none;
}
blockquote, q {
quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
content: '';
content: none;
}
table {
border-collapse: collapse;
border-spacing: 0;
}