所以基本上我有一个设置,以以下方式吐出代码..
<div class="parent">
<div class="subparent">
<div class="TARGETCLASS"></div>
</div>
<div class="subparent">
<div class="TARGETCLASS"></div>
</div>
</div> //close for the parent class
现在我想要做的是设计一种方式之上的“TARGETCLASS”和另一种方式第二位的“TARGETCLASS”。我尝试了第 n 个孩子,但无法达到我正在寻找的结果。无法向现有的“TARGETCLASS”类添加其他类或 ID。否则我不会发布这个问题:)
此外,“子父”类也是相同的。对于两个目标类。这就是问题 预先感谢您抽出宝贵时间为我回答这个问题。
干杯!
我会像这样使用 nth-of-type 选择器:
.parent{}
.parent > .subparent {} //targets both subparents
.parent > .subparent:nth-of-type(2) {} //targets the second subparent
.parent > .subparent:nth-of-type(2) > .TARGETCLASS{} //targets the child of the second subparent
第 nth-of-type() 选择器使您能够为系列中的特定元素设置样式,在这种情况下,我们定位第二个 .subparent 然后指定我们需要的子元素。我希望这有帮助!
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句