css first-child selector help
Is there a way to highlight the first link, and only the firs开发者_StackOverflowt link, directly below a list item with class "selected"?
Here is my js fiddle
Yeah, use
.selected > a:first-child {
/* CSS */
}
>
limits the selector to direct children.
You can use the first-child selector.
.selected > a:first-child {
color: red;
}
You can use nth-child()
to do this as well.
.selected > a:nth-child(1) {
color: red;
}
or
.selected > a:nth-child(1n - 1) {
color: red;
}
:)
.selected > a:first-child {color:red;}
This should work in your case.
精彩评论