2015-06-02 88 views
-1

功能:將禁用的背景顏色從灰色更改爲白色。爲什麼CSS!important在我的用例中不起作用?

已選擇解決方案: 我已經添加在CSS顯示如下的類:

.whiteBackground{ 
background-color: white !important; //As Pure CSS API also have rules for disabling so i mark it as important 
} 

我已經加入以下在JQuery的代碼禁用選擇上的基:

$("#listOfFruits").attr('disabled',(fruitsListSize === 0)); //This fuitsListSize is returning 0 in my case, so it will be true 
$('#listOfFruits').addClass((fruitsListSize === 0)?"whiteBackground":""); //listOfFruits is name of <select> 

上面的代碼不不行。

我檢查過使用Firebug,發現下面的純CSS代碼正在實施,我的班級不在列表中。

.pure-form select[disabled]{ 
background-color: grey (code); 
cursor: not-allowed; 
} 

HTML顯示我的類名:

<select multiple="multiple" style="width:250px" name="listOfFruits" id="listOfFruits" disabled="disabled" class="whiteBackground"> 

回答

1

下面的代碼完全爲我工作:

.pure-form select[disabled].whiteBackground { 
background:white !important ; 
} 
0

嘗試

select[disabled] 
{ 
background:white; 
} 
+0

將它不會被應用在所有選擇? – fatherazrael

+0

@fatherazrael是的,添加更多的上下文,以更好地定位您的選擇。但是這更好。 –

+0

@AndréSnedeHansen 謝謝。但我不希望所有選擇。讓純CSS工作在所有選擇上,特別選擇我希望我的CSS工作。 – fatherazrael