問題描述
這不是記錄在案還是不可能?
Is this not documented or just not possible?
#parent {
#child {
width: 75%;
.additional_parent_class & {
width: 50%;
}
}
}
這基本上會變成:
.additional_parent_class #parent #child {
width: 50%;
}
雖然這很有意義,因為與符號的實現及其使用方式有關.如果我試圖讓它實現這一點怎么辦:
While this makes sense because of the implementation of the ampersand and how it's used. What if I'm trying to get it to achieve this:
#parent.additional_parent_class #child {
width: 50%;
}
我能夠做到這一點的唯一方法是在子聲明之外編寫另一條規則:
The only way I have been able to achieve this is by writing another rule outside of the child declarations:
#parent{
#child {
width: 75%;
}
&.additional_parent_class #child {
width: 50%;
}
}
雖然在此實現中這不一定是麻煩事",但如果#child 有自己的子項現在需要在兩個規則中復制,這似乎會適得其反.
While this isn't necessarily a 'pain in the butt' in this implementation, it seems counter productive if #child has children of its own that will now need to be duplicated in both rules.
無論如何,也許我只是挑剔,但如果有更多的方法可以遍歷選擇器,那就太好了.
Anyway, maybe I'm just being picky, but it would be great if there were more ways to traverse through the selectors.
推薦答案
雖然目前還不可能,但這個和許多對 &
語法的類似改進計劃在 Sass 3.3 中發布.您可以在這里關注關于 Sass 問題的功能討論.
Although it is not currently possible, this and many similar improvements to the &
syntax are slated for release in Sass 3.3. You can follow the discussion about the feature on the Sass issue here.
這篇關于嵌套選擇器內的與號(父選擇器)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!