<分区>
<分区>
<div class="tabs">
<div class="title">A</div>
<div class="title">B</div>
<div class="content">Something</div>
</div>
如何在不重组我的 html 的情况下选择 B
标题,并且可能会添加 C、D、E 和更多标题。我在 css 下试过它不起作用
最佳答案
使用nth-child
和nth-of-type
选择器。根据您的需要选择以下任何一项。
解决方案:1
.tabs :nth-child(2){
color:red;
}
解决方案:2
.tabs .title:nth-child(2){
color:red;
}
解法:3
.tabs .title:nth-of-type(2){
color:red;
}
关于html - 展开元素上的最后一个子选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49913141/