我正在尝试根据元素的几率和偶数来更改页面上元素的背景颜色。

但是,我的CSS根本不改变背景颜色,我也不明白为什么!

这是我的fiddle

这是我的CSS代码:

.miles:nth-child(odd) {
    background-color:#af1f32;
}

.miles:nth-child(even) {
    background-color:#f7b637;
}


我什至尝试了这个,但还是没用:

.ite .miles:nth-child(odd) {
    background-color:#af1f32;
}

.ite .miles:nth-child(even) {
    background-color:#f7b637;
}


我也这样尝试过,但没有成功:

.miles:nth-of-type(odd) {
    background-color:#af1f32;
}

.miles:nth-of-type(even) {
    background-color:#f7b637;
}


有人可以就这个问题提出建议吗?

提前致谢...

最佳答案

尝试,

.ite:nth-child(odd) .miles {
    background-color:#af1f32;
}

.ite:nth-child(even) .miles {
    background-color:#f7b637;
}

关于css - CSS:奇怪,甚至不触发?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/39916334/

10-11 13:49