在*上应用“重置”样式

时间:2014-01-17 14:57:11

标签: css css-selectors css-reset

将全局样式应用于所有元素是否有任何缺点?

*{
  margin: 0;
  padding: 0;
  border: 0;
  list-style: none;
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
}

1 个答案:

答案 0 :(得分:2)

*是所谓的“重型”选择器。但不幸的是,没有其他方法可以将边框模型应用于几行代码中的所有元素。 谈论填充/边距和列表式重置 - 更好地使用www.cssreset.com/

中的一些常用技术

*边框可以在这里应用,在Eric Meyer的重置CSS v2.0

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