2015-05-12 29 views
1

我使用LESS。嵌套僞類像懸停/集中到超鏈接LESS

我怎麼能說懸停/焦點屬於第一個> a我可以以某種方式把懸停/焦點放在> a裏面?

> ul > li > a { 
     color: #fff; 
     text-decoration: none; 
    } 

    > a:hover, > a:focus { // login, register 
     background-color: @navbar-background-color; 
    } 
+1

巢它的第一個規則中,並使用父選擇器(如':懸停,&:重點{...}' – Harry

回答

1

可以使用LESS's Parent Selector (&)以包括屬於當前選擇器選擇器:

&操作者表示嵌套規則的父選擇器和施加改性類或僞時是最常用的類到現有的選擇器。

> ul > li > a { 
    ... 

    &:hover, 
    &:focus { 
     ... 
    } 
} 
+0

這看起來很酷! – Elisabeth