【发布时间】:2019-03-09 15:02:49
【问题描述】:
我正在使用 BEM Scss 请解释如何在第 n 个子元素内进行选择。
我尝试了以下格式,但它不适合我
<div class="bookearly-container" >
<div class="row bookearly-container__row">
<div class="col-xs-12 col-md-4 bookearly-container__col">
<div class="bookearly-container__discountcontainer">
</div>
<div class="bookearly-container__discountcontainer">
</div>
<div class="bookearly-container__discountcontainer">
</div>
</div>
</div>
</div>
我的 BEM Scss 我添加了 nth-child 3rd element 无效的子元素:
.bookearly-container {
&__row {
margin-bottom: 4.6rem;
& > :nth-child(3) {
&__discountcontainer { -- this element not selected
&:before {
display: none;
}
}
}
}
}
你能解释一下如何选择吗?提前致谢。
【问题讨论】:
-
你能在你的问题中添加相关的html吗?
-
你看过你生成的css吗?编译后的选择器看起来像:
.bookearly-container__row > :nth-child(3)__discountcontainer:before{} -
所以
&__discountcontainer应该是.bookearly-container的一个元素?