2016-10-24 38 views
1

我正在解決我遇到的問題textareawysihtml使用不同選擇器時,工作CSS不適用於元素?

目前,我有這樣的事情

<textarea class="wysihtml wysi-fix" required></textarea> 

我有一些CSS,看起來像這樣

.wysi-fix{ 
//some css here 
} 

的.wysi修復CSS工作在textarea的,但如果我改變textarea的到...

<textarea class="wysihtml" required></textarea> 

,我更改CSS來

.wysihtml[required]{ 
//the css goes here 
} 

儘管兩個選擇器都在HTML頁面上選擇相同的元素,但CSS不再有效。如果有幫助,我使用SASS而不是香草CSS。關於發生了什麼的任何想法?

+1

.wysihtml [required = required] { // the css在這裏 } – Araz

+0

並使textarea required =「required」 – Araz

+0

另外,是不是'.wysihtml:required {}'? – somethinghere

回答

3

According to MDN,你的屬性選擇器應該工作。

可能你必須使用[required="required"]作爲屬性選擇與像0​​標記:

.wysihtml[required="required"]{ 
    //the css goes here 
} 

但更好的方法是使用:required僞類:

.wysihtml:required{ 
    //the css goes here 
} 
+2

是否需要爲「required」設置一個值?我相信'.class [attr]'應該可以識別屬性而不管它的值,對嗎? – somethinghere

+1

好點,據我所知不是必需的......我的回答更多的是對可能的解決方案的建議,而不是解釋,爲什麼'.wysihtml [required]'不工作...... – andreas

+0

是'。 wysihtml [required =「required」] css對於老版本的瀏覽器來說是一個更安全的選項?假選擇器是CSS 3.0正確的嗎? –

2

嘗試.wysihtml:required代替.wysihtml[required]