【问题标题】:Why does blueprint css define a div.class and class with the same styling?为什么 blueprint css 定义一个 div.class 和 class 具有相同的样式?
【发布时间】:2010-12-28 01:31:17
【问题描述】:

在蓝图 CSS 框架的链接代码中,为 div.class 选择器和 .class 选择器定义了一个样式。这不是多余的吗?还是有更微妙的原因用两个选择器定义类?

https://github.com/joshuaclayton/blueprint-css/blob/master/blueprint/src/grid.css(第 229-235 行)

/* In case you need to add a gutter above/below an element */
div.prepend-top, .prepend-top {
  margin-top:1.5em;
}
div.append-bottom, .append-bottom {
  margin-bottom:1.5em;
}

【问题讨论】:

    标签: css html css-selectors blueprint-css


    【解决方案1】:

    有趣的问题。我没有使用过蓝图,但是如果您选择覆盖div.prepend-top 或 .prepend-top,则只会覆盖该选择器的样式。

    这意味着这样做:

    .prepend-top { margin-top: 1em; }
    

    将保留 <div>s 的样式,该类不受影响(仍然是 1.5-em 上边距),因为 div.prepend-top 是一个更具体的选择器,因此将优先于 <div> 元素。

    然后这样做:

    div.prepend-top { margin-top: 1em; }
    

    由于div 类型选择器,该类的其他元素的样式不受影响。 append-bottom 类也是如此。

    同样,我没有使用蓝图,但我认为这与它期望您的 HTML 的结构方式有关。

    【讨论】:

    • 我明白了,这很有意义(这样做是为了或多或少的特异性)。谢谢!
    猜你喜欢
    • 2017-08-21
    • 2011-11-25
    • 1970-01-01
    • 2020-02-13
    • 2021-07-22
    • 2019-04-04
    • 2012-11-18
    • 2010-10-07
    • 2010-10-07
    相关资源
    最近更新 更多