初始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;
box-sizing: border-box; /* 保证元素的宽高只包含内容区域和内边距,不包含边框和外边距 */
}
/* HTML5 显示设置 */
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;
}
这段代码重置了所有元素的边距、填充、边框和字体大小,并确保了列表、引用、表格的边框合并,同时移除了引用和块引用的装饰符。这样做可以确保跨浏览器的一致性,从而减少样式问题的调试时间。