2015-06-16 40 views
1

下面的代碼:我怎樣纔能有多個選擇器混合?

.positionBase (@name,@size: 16px,@position: 0) { 
    [disabled] [email protected]{name}, .disabled [email protected]{name}, [email protected]{name} { 
     background-position: @position*@size [email protected]; 
    } 

    [email protected]{name} { 
     background-position: @position*@size 0; 
    } 

    [email protected]{name}.dark { 
     background-position: @position*@size -2*@size; 
    } 

    [email protected]{name}.dark:hover, a:hover [email protected]{name}.dark, button:hover [email protected]{name}.dark, .button:hover [email protected]{name}.dark, .interactable:hover [email protected]{name}.dark { 
     background-position: @position*@size -3*@size; 
    } 
} 

* { 
    .positionBase(testing,16px,0) 
} 

產生如我所期望的:

* [disabled] .icon.testing, 
* .disabled .icon.testing, 
* .disabled.icon.testing { 
    background-position: 0px -16px; 
} 
* .icon.testing { 
    background-position: 0px 0; 
} 
* .icon.testing.dark { 
    background-position: 0px -32px; 
} 
* .icon.testing.dark:hover, 
* a:hover .icon.testing.dark, 
* button:hover .icon.testing.dark, 
* .button:hover .icon.testing.dark, 
* .interactable:hover .icon.testing.dark { 
    background-position: 0px -48px; 
} 

如何擺脫*前綴,只是有選擇不帶前綴?

東西不起作用:

.positionBase(testing,16px,0)

* { 
    .positionBase(testing,16px,0) 
} 

{ 
    .positionBase(testing,16px,0) 
} 

我的谷歌foo是弱,我發現沒有什麼會讓我認爲這是可能的,在這種情況下,我想使用*前綴,但這對性能也非常不利。有任何想法嗎?

感謝

回答

2

只是.positionBase(testing,16px,0);應該工作(請務必在末尾分號這可能會導致如果離開少編譯失敗!)我測試了它這裏

http://lesstester.com/,它工作得很好。

.positionBase (@name,@size: 16px,@position: 0) { 
    [disabled] [email protected]{name}, .disabled [email protected]{name}, [email protected]{name} { 
     background-position: @position*@size [email protected]; 
    } 

    [email protected]{name} { 
     background-position: @position*@size 0; 
    } 

    [email protected]{name}.dark { 
     background-position: @position*@size -2*@size; 
    } 

    [email protected]{name}.dark:hover, a:hover [email protected]{name}.dark, button:hover [email protected]{name}.dark, .button:hover [email protected]{name}.dark, .interactable:hover [email protected]{name}.dark { 
     background-position: @position*@size -3*@size; 
    } 
} 

.positionBase(testing,16px,0); 
+0

黨吧!只要SO讓我接受這一點,我會......謝謝 – Nate

+0

所以顯然你不需要在EVERY線後的半色,只是在支架集中的線或獨立線......道德:總是使用分號。 – Nate

+0

*總是使用分號*是遵循非常好的生活格言 –

相關問題