CSS: apply background color to first-child of ul l

2019-07-13 06:53发布

I want to apply red background color to 1st li only i have tried several method but not able to get what i want:

#rightmxmenu > ul > li:first-child > {background-color:#ca212d;}
#rightmxmenu > li:first-child > {background-color:#ca212d;}

it does not affect anything

here is my code and css http://jsfiddle.net/gwdp3/1/

hope any expert can tell me what should i need to change.

标签: css css3 menu
4条回答
我想做一个坏孩纸
2楼-- · 2019-07-13 07:31

You may want to try using a class selector in the css and apply it to all your "first" menu items

.firstItem
{background-color:#ca212d;}

and in HTML use

<ul>
<li class ="firstItem"></li></ul>
查看更多
爱情/是我丢掉的垃圾
3楼-- · 2019-07-13 07:33

Remove the last ">" made it for me.

#rightmxmenu > ul > li:first-child { background-color:#ca212d; }
#rightmxmenu > li:first-child { background-color:#ca212d; }

Hope this helps.

查看更多
看我几分像从前
4楼-- · 2019-07-13 07:51

Change this:

#rightmxmenu > ul > li:first-child > {
    background-color:#ca212d;
}

to this:

#rightmxmenu > ul > li:first-child  {
    background-color:#ca212d;
}

jsFiddle example

You don't need the trailing >.

查看更多
成全新的幸福
5楼-- · 2019-07-13 07:51

This should work just fine:

#rightmxmenu ul li:first-child {
background-color:#ca212d;
}
查看更多
登录 后发表回答