为什么CSS!important在我的用例中不起作用?

时间:2015-06-02 05:29:31

标签: javascript jquery html css

功能:将禁用的背景颜色从灰色更改为白色。

选择解决方案: 我在CSS中添加了一个类,如下所示:

myView

我在JQuery中添加了以下代码,禁用基于以下内容的选择:

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

上述代码不起作用。

我已经使用Firebug进行了检查,发现以下Pure CSS代码已经实现,我的类不在列表中。

$("#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>

HTML显示我的班级名称:

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

2 个答案:

答案 0 :(得分:1)

以下代码对我来说非常合适:

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

答案 1 :(得分:0)

尝试

select[disabled]
{
background:white;
}
相关问题