【发布时间】:2017-10-26 10:35:45
【问题描述】:
我对 scss 有点陌生,我的行容器中的行有这种基本样式。
.rows-container{
border-bottom:2px ridge grey;
}
.row{
height:30px;width:100%;
&:hover div{
background-color:lightgrey;
}
&:nth-child(odd){
background: white;
}
&:nth-child(even){
background: #e0e0e0;
}
}
使用以下 html 非常简单:我遗漏了一些不重要的 html。
<div class="rows-container">
<div class="row></div> //white
<div class="row></div> //grey
<div class="row></div> //white
<div class="row></div> //grey etc...
</div>
但现在我添加了子行
<div class="rows-container">
{{each rows}}
<div class="row"></div> //parent row
{{each childs}}
<div class="subitem"></div> //several rows from the same table which have a parent_id connected to the current row.
{{#each}}
{{#each}}
</div>
我打算在点击时切换子项。但是当没有子项可见时(子项有自己的颜色),'.rows'奇数/偶数会被弄乱。现在我认为这是因为第 n 个子奇数/偶数是在容器中的所有行/子项上计算的,而不仅仅是 .row(s)。 有没有办法对 .rows 设置奇数/偶数样式,但从奇数/偶数旋转中排除 .subitems?我在想也许有一种方法可以在 scss 中使用 :not() ,但到目前为止我还没有成功。
【问题讨论】:
-
使子项成为行的子项?
-
如果我真的必须这样做,我想我可以,但它会破坏行的整体响应能力。现在我在想 jquery...我可以为 css 相关的东西创建一个 .js 文件
-
CSS 没有
nth-of-class选择器,因此您无法选择所有其他类。 -
我会接受这个答案,我会想办法np
-
@MaartenKuijper 你可以制作
.rows<section>和儿童<div>。作为不同的标签,您可以通过以下方式进行更多控制:section:nth-of-type(even)。现在<div>不会被包含在选择中,只有<section>