在渲染 html 元素时,规范化 css 会尝试消除浏览器之间的差异。许多浏览器都有“预设置”:p 和h-元素有垂直边距,列表也有一些边距和填充。 em 和 strong 标签具有粗体字重。
所有这些预先设置都被重置,以便您在所有浏览器中拥有一致的工作基础。
JSFiddles normalize.css 看起来像这样:
body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,form,fieldset,input,textarea,p,blockquote,th,td {
margin:0;
padding:0;
}
table {
border-collapse:collapse;
border-spacing:0;
}
fieldset,img {
border:0;
}
address,caption,cite,code,dfn,em,strong,th,var {
font-style:normal;
font-weight:normal;
}
ol,ul {
list-style:none;
}
caption,th {
text-align:left;
}
h1,h2,h3,h4,h5,h6 {
font-size:100%;
font-weight:normal;
}
q:before,q:after {
content:'';
}
abbr,acronym { border:0;}
规范化 css 的意义值得商榷,因为您必须在样式表中手动重新声明每种样式(即使是那些有意义的预设,例如在 em 和 strong 处理的标签上的简单 font-weight浏览器同样如此)。
我使用Eric Meyer's reset 有一段时间,但停止使用它,因为它重置了太多需要再次重新声明的样式。 IMO 不值得。
要获得真正好的style-normalizer,请查看http://html5boilerplate.com/ 的 style.css。