使用子选择器的菜单css

使用子选择器的菜单css,css,menu,Css,Menu,我有以下菜单: <ul class="top-menu"> <li><a_href="/Products" title="Products"><span>Products</span></a><ul> <li><a_href="/Products/List" title="Product List"><span>Product List</span></a&g

我有以下菜单:

<ul class="top-menu">
<li><a_href="/Products" title="Products"><span>Products</span></a><ul>
<li><a_href="/Products/List" title="Product List"><span>Product List</span></a></li>
</ul>
</li>
<li><a_href="/Customers" title="Customers"><span>Customers</span></a></li>
</ul>
但它不起作用。
谢谢。

n子选择器设置在子元素上,而不是父元素上

为了使您的示例起作用,我在li上使用了第n个子选择器,而不是ul,如下所示:

ul.top-menu li:nth-child(1) a
{
    width:135px;
    background-position:0 0;
}

当然还有“它以什么方式不起作用?发生了什么事?你能在(或)上制作一个演示页面吗?”?
ul.top-menu li:nth-child(1) a
{
    width:135px;
    background-position:0 0;
}
/* desired top-level-only styles go here */
ul.top-menu>li>a
{
    width:135px;
    background-position:0 0;
}