【发布时间】:2015-06-18 10:01:19
【问题描述】:
我正在开发一个使用内部 UI 库的项目。在其中一个 CSS 文件中,我看到了一些看起来很奇怪的东西。 为了简单起见,我使用基本的 html 元素和相应的 css:
CSS:
div{
border:1px solid black;
width:100px;
height:100px;
}
.parent
//some comment exists here
.child{
background-color: red;
}
.anotherdiv{
background-color: blue;
}
和HTML:
<div class='parent same'>Parent
<div class='child'>Child</div>
</div>
<div class='anotherdiv'></div>
当我尝试在 Firefox 上检查上述内容时,我在 CSS 控制台下收到以下警告。
悬空组合器:由于选择器错误而忽略了规则集
我试图向后解决问题,即对于给定的 CSS:
.parent
//some comment exists here
.child{
background-color:red;
}
我认为上面会解决
.parent .child{
background-color:red; //applied on inside level element
}
或者,
.parent.child{
background-color:red; //applied on same element
}
但其中任何一个都没有应用。
并且,为具有类anotherdiv 的div 定义的规则集运行良好。
我想知道浏览器是如何读取 CSS 的,以及在到达某些弯曲线时,它是如何解决的,以及 CSS 中的以下规则集是如何产生影响的。
更新
我交叉检查了文件的类型,结果是.SCSS,下面是我觉得奇怪的地方
.accordion-toggle
// Inner needs the styles because you can't animate properly with any styles on the element
.accordion-inner {
padding: 9px 15px;
border-top: 1px solid #e5e5e5;
}
抱歉之前的误会!
【问题讨论】:
-
//不是 CSS 中的注释,所以你不妨写.parent ???? .child -
这在 CSS 中是无效的,但它会在一些 CSS 预处理器(如 SASS 或 LESS)中工作(稍加修改)。
-
@PeeHaa 与
/*....*/一起,我可能已经看到//被用作指定cmets。如果不是,那么它的可能用途是什么? -
在 CSS 中没有这样的用法。如果你认为你曾经看到它是错误的(很可能是因为某些语言确实使用它)
标签: html css google-chrome mozilla