【问题标题】:CSS reset: Why do headings ignore * { margin: 0; }?CSS 重置:为什么标题会忽略 * { margin: 0; }?
【发布时间】:2016-02-06 13:19:54
【问题描述】:

标准化很酷。但我非常讨厌边距/填充/框大小。

当我设置* { margin: 0; } 时,它似乎会适当地重置除标题(h1、h2 等)元素之外的每个元素。

发生了什么事?如何重置这些元素?

【问题讨论】:

  • It should work。也许您稍后会覆盖这些样式?你能发布你的完整标记吗?
  • 你试过检查元素吗?
  • @Vucko 你是对的!我是个白痴。 github.com/necolas/normalize.css/blob/master/… 我真的厌倦了 Normalize 的边缘废话。即使其他 html5 元素都没有获得边距,他们也会将边距应用于 <figure>... 将您的评论作为答案,我会接受其他答案是如何完全错过重点的。人们甚至会在回答之前阅读这些问题吗?

标签: css reset typography


【解决方案1】:

我喜欢在这里像这个坏男孩一样使用完整的 CSS 重置 - http://meyerweb.com/eric/tools/css/reset/ 不过,您必须手动设置所有内容的样式,包括标题和列表

【讨论】:

    【解决方案2】:

    浏览器有不同的默认样式表。

    这就是为什么开发人员经常使用某种类型的 css 重置,例如 normalize.css

    如果您想消除所有浏览器中不需要的边距,请尝试添加以下内容(或 normalize.css):

    *, html, body {
        margin:0;
        padding:0;  
    }
    

    还有很多其他的 CSS 重置选项 - Eric Meyers 想出了一个不错的选项。

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

    【讨论】:

      猜你喜欢
      • 2011-07-20
      • 1970-01-01
      • 2023-02-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-12
      相关资源
      最近更新 更多