2017-03-17 65 views
1

在SASS的班級選課中,我想選擇家長的兄弟姐妹。在SASS中,如何引用標籤選擇?

.bw-textarea { 
    height: 150px; 
    padding: 10px; 
    overflow-y: auto; 
    background: white; 
    text-align: left; 
    width: 100%; 
    border: 1px solid #eeeeee; 
    font-size: 12px !important; 
    color: #666666; 

// textarea:disabled & { 
//  background: #efefef; 
// } 
} 

上述SASS代碼的編譯,

.bw-textarea textarea:disabled { 
    background: #efefef; 
} 

但是我想表明這樣的CSS代碼的結果......

如何SASS選擇這樣嗎?

textarea.bw-textarea:disabled { 
    background: #efefef; 
} 

回答

2

這是你找什麼:

.bw-textarea { 
    height: 150px; 
    padding: 10px; 
    overflow-y: auto; 
    background: white; 
    text-align: left; 
    width: 100%; 
    border: 1px solid #eeeeee; 
    font-size: 12px !important; 
    color: #666666; 

    &:disabled { 
     background: #efefef; 
    } 
} 

看看這個SO回答律的嵌套僞選擇

Sass parent selector and hover?

當然檢查更多的想法sass docs

https://sass-lang.com/documentation/file.SASS_REFERENCE.html

+0

這是一個易於使用的正確答案並編寫更少的代碼。 – Brad

3

在這種情況下,您必須使用@root。這是很簡單的

link將給出一個明確的想法這個選擇

.bw-textarea { 
    @at-root textarea#{&}:disabled{ 
    background: cyan; 
    } 
} 

這將編譯到

textarea.bw-textarea:disabled { 
    background: cyan; 
} 

See this PEN

+0

'@ at-root'是一個非常棒的工具,但它對這個問題的矯枉過正 – raykrow