<分区>
标签 html css css-selectors
<分区>
我想为第 n 个子标志应用绿色
<div id="axis">
<div class="super"></div>
<div class="flag">flag 1</div><!-- I want this text to be green-->
<div class="super"></div>
<div class="flag">flag 2</div>
<div class="super"></div>
<div class="flag">flag3</div>
<div class="super"></div>
</div>
CSS:
#axis{
color:red;
}
#axis .flag:nth-of-type(1){
color:green;
}
#axis .flag:nth-child(1){
color:green;
}
我在这两种情况下都试过了,但都没有用......
最佳答案
另一种方式DEMO
<ul id="axis">
<li class="flag">flag 1</li>
<li class="flag">flag 2</li>
<li class="flag">flag3</li>
</ul>
.flag {
list-style:none;
color:red;
}
.flag:nth-of-type(1) {
color:green;
}
关于html - css 中的第 nth-of-type 和 nth-child 无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25908629/