开发者

css first-child selector help

开发者 https://www.devze.com 2023-03-26 14:50 出处:网络
Is there a way to highlight the first link, and only the firs开发者_StackOverflowt link, directly below a list item with class \"selected\"?

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消