简化了ID和子组合子



我有7个ID具有相同的子组合子,我如何简化它,这样我就不必像下面这样写了:

#section-monday > div > div > div:nth-child(1),
#section-tuesday > div > div > div:nth-child(1),
#section-wednesday > div > div > div:nth-child(1),
... {}

我可以以某种方式将ID分组,并使用子组合子只跟随它们一次吗?

"#section-monday, #section-tuesday, #section-wednesday" > div > div > div:nth-child(1){}

您可以使用部分id文本作为选择器,但是在这种的情况下应该使用类

[id*="section-"] > div > div > div:nth-child(1){
border:1px solid red;
}
<div id="section-monday">
<div>
<div>
<div>
:D
</div>
<div>
:(
</div>
</div> 
</div> 
</div>
<div id="section-tuesday">
<div>
<div>
<div>
:D
</div>
<div>
:(
</div>
</div> 
</div> 
</div>
<div id="section-monday">
<div>
<div>
<div>
:D
</div>
<div>
:(
</div>
</div> 
</div> 
</div>
<div id="section-wednesday">
<div>
<div>
<div>
:D
</div>
<div>
:(
</div>
</div> 
</div> 
</div>

最新更新