html - css 中的第 nth-of-type 和 nth-child 无法正常工作

标签 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;
}

我在这两种情况下都试过了,但都没有用......

Fiddle

最佳答案

另一种方式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/

上一篇:javascript - 使用 javascript(或 jQuery)选择和操作 CSS 伪元素,例如::before 和::after

下一篇:html - 尝试居中对齐 Ebay 模板 - 但不起作用

相关文章:

html - 带有 HTML 格式的自动电子邮件

html - 表格在 Firefox 中错位

html - Bootstrap 按钮在页面变小时换行

css - 我应该在 <main> 标签上添加一个类吗?

jQuery 选择器帮助 - 我可以通过单击元素生成选择器吗?

javascript - 用 HTML 元素替换文本标记

html - Web 响应式 - 转换表格标题

html - 设备分辨率和固定宽度(以像素为单位)

html - 顶部栏不显示响应式菜单 - 基础 5

css - 设置活跃 Superfish 菜单选项的背景样式