2016-07-26 36 views
0

嗨,我只想在班級啤酒中選擇「鏈接」,但它總是從子菜單中選擇所有鏈接。我嘗試css只能選一個

.beers:first-child  does not work 
    .beers a:nth-child(1)  does not work 
    .beers a:first-of-type (this apply to all the links of sub-menu) 

<ul> 
    <li class="beers"><a>Link</a> only here 
     <ul class="sub-menu"> 
      <li ><a></a></li>  not here 
      <li><a></a></li>  not here 
     </ul> 
    </li> 
    <li ><a></a></li> 
    <li ><a></a></li> 
</ul> 

請幫我

+0

您想選擇素t in CSS or Jquery –

+0

我想在css中選擇它 – pexichdu

回答

2

如果你想如果你想使用li使用樣式a

.beers > a{color:green;} 

已覆蓋

li.beers{ color:green;} 
li.beers ul li{ color:black;} 
1

你必須保持的元素水平。嘗試下面的一個。

.beers>一

2

你可以從小孩得到第一個元素如下:

<style> 
.beers >a { 
    background-color:red; 
} 

0
.beers:first-child 

.beers li:first-child 

有了:

<ul class="beers"> 
<li><a>Link</a> only here 
    <ul class="sub-menu"> 
     <li ><a></a></li>  not here 
     <li><a></a></li>  not here 
    </ul> 
</li> 
<li ><a></a></li> 
<li ><a></a></li> 

+0

class =「beers」in li not in ul and I can not change that, 我試過beers.first-child已經 – pexichdu