为什么blueprint css定义一个div.class和class具有相同的样式?
在蓝图 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;
}
In the linked code for the blueprint CSS framework, there is a style defined for a div.class
selector and just the .class
selector. Isn't this redundant? Or is there a more subtle reason for defining the class with two selectors?
https://github.com/joshuaclayton/blueprint-css/blob/master/blueprint/src/grid.css (lines 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;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有趣的问题。我没有使用过 Blueprint,但是如果您选择覆盖
div.prepend-top
或.prepend-top
,则仅覆盖该选择器的样式将被覆盖。这意味着这样做:
将保留该类的
样式不受影响(仍然是 1.5-em 上边距),因为
div.prepend-top
是更具体的选择器,因此元素优先。
这样做:
由于
div
类型选择器,该类的其他元素的样式将不受影响。对于append-bottom
类也是如此。同样,我没有使用过 Blueprint,但我认为它与它期望 HTML 的结构方式有关。
Interesting question. I've not used Blueprint, but then if you choose to override either
div.prepend-top
or.prepend-top
, only that selector's styles will be overridden.That means doing this:
Will leave the styles for
<div>
s with that class unaffected (still a 1.5-em top margin), becausediv.prepend-top
is a more specific selector and so will take precedence for<div>
elements.And doing this:
Will leave the styles for other elements with that class unaffected, because of the
div
type selector. Likewise for theappend-bottom
class.Again I've not used Blueprint, but I think it has something to do with how it expects your HTML to be structured.