为什么blueprint css定义一个div.class和class具有相同的样式?

发布于 2024-10-09 10:48:47 字数 529 浏览 1 评论 0原文

在蓝图 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

大海や 2024-10-16 10:48:47

有趣的问题。我没有使用过 Blueprint,但是如果您选择覆盖 div.prepend-top .prepend-top,则仅覆盖该选择器的样式将被覆盖。

这意味着这样做:

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

将保留该类的

样式不受影响(仍然是 1.5-em 上边距),因为 div.prepend-top 是更具体的选择器,因此

元素优先。

这样做:

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

由于 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:

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

Will leave the styles for <div>s with that class unaffected (still a 1.5-em top margin), because div.prepend-top is a more specific selector and so will take precedence for <div> elements.

And doing this:

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

Will leave the styles for other elements with that class unaffected, because of the div type selector. Likewise for the append-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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文