css - global css reset * { margin : 0; padding: 0; }? 的缺点是什么

标签 css xhtml cross-browser

global css reset * { margin: 0; 的缺点是什么?填充:0; }?

人们更喜欢 eric meyer css。

这是 eric mayer 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, font, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td {
    margin: 0;
    padding: 0;
    border: 0;
    outline: 0;
    font-weight: inherit;
    font-style: inherit;
    font-size: 100%;
    font-family: inherit;
    vertical-align: baseline;
}
/* remember to define focus styles! */
:focus {
    outline: 0;
}
body {
    line-height: 1;
    color: black;
    background: white;
}
ol, ul {
    list-style: none;
}
/* tables still need 'cellspacing="0"' in the markup */
table {
    border-collapse: separate;
    border-spacing: 0;
}
caption, th, td {
    text-align: left;
    font-weight: normal;
}
blockquote:before, blockquote:after,
q:before, q:after {
    content: "";
}
blockquote, q {
    quotes: "" "";
}

是不是有点具体和沉重。我从不使用其余部分中的许多元素,例如 block 引用和标题。

更新: 和 eric reset 重置 58 个元素的 9 个属性。是不是也很慢,就像人们谈论全局重置一样。

使用这个有什么缺点

* { margin: 0; padding: 0; }
select { min-width:1.5em; }

最佳答案

问题是有些元素需要边距和/或填充才能正确显示,而人们忘记将它们设置回去。此外,对于许多元素,您将设置自己的样式,覆盖重置,因此重置是多余的;您应该改为按照您想要的方式设置样式。

我经常看到的一个问题是列表。如果您盲目地应用重置,列表的元素符号将出现在包含元素的外部,这总是困扰着我:

    +--------------------+
    | Some paragraph,    |
    | with text.         |
    |                    |
   *| One                |
   *| Two                |
   *| Three              |
    +--------------------+

也许有些设计师是故意这样做的,但我认为很多时候我看到这个,是因为有人盲目地应用了重置而没有考虑它会对列表项的缩进产生什么影响。如果你寻找它,你会发现它无处不在;并且几乎总是,您看到它的网站使用 CSS 重置。有关如何正确设置列表格式的更多信息,请参阅 Consistent List Indentation on the Mozilla Developer Center .

另一个问题是,在进行重置后,有时会出现模糊的元素,人们不记得将边距应用回。例如,<dl>元素;它的默认样式不是很好,但它至少可以让您区分 <dt><dd>其中的元素。如果您应用重置,您将失去它并最终将所有内容毫无区别地挤在一起。 Stack Overflow 的重置就是这样做的,例如,制作 <dl>元素几乎没用:

任期
定义
任期
定义


Stack Overflow 的重置在 <dl> 上也没有任何顶部或底部边距。元素,并且只有 <p> 的底部边距;所以我不得不添加一个额外的 <br>为了防止以上<dl>免于遇到这一段。

如果您确实使用了重置,请务必小心确保所有 HTML 元素确实以合理的方式显示。并删除重置中被您添加的后续规则覆盖的部分;没有真正的理由重置 <b><i> ,然后再申请 font-weightfont-style给他们,如果您将边距重置为 0然后将其设置为 2 em , 那么为什么不删除重置为 0

关于css - global css reset * { margin : 0; padding: 0; }? 的缺点是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2094907/

相关文章:

javascript - Click 事件和 MouseOut 事件在 Chrome 中不起作用

css - 不同浏览器上的视差滚动图像

html - 为什么我的搜索栏中的占位符文本没有出现在 Firefox 中

css - 站点缩放问题 : not all of the components scaling as they should

css - 如何正确使用 <col> 标签,所有浏览器都支持吗?

CSS:删除图像周围的边框搞砸了图像定位

javascript - 通过 JavaScript 添加 -webkit -moz -ms -o css 规则?

HTML - 使用 "//domain.com"而不是 "https://domain.com"或 "http://domain.com"

CSS:无法转换下拉菜单

html - 使用 CSS 选择器在第一个 span 内部标签后冒号