What CSS selector can be used to select all odd elements inside a parent, but which are not necessarily siblings?
-
I couldn't get it down to single selector, but with two...
.parent > .element:nth-of-type(2n){
background:#afa !important;
}
.parent > div:nth-of-type(2n) > .element {
background:#afa !important;
}
View it on JSFiddle
讨论(0)
-
While it uses JavaScript, you could style the odd element without altering your markup:
$('.parent .element:odd').css('font-weight', 'bold');
http://jsfiddle.net/ansonhoyt/MfxYF/
讨论(0)