更改Duallistbox中单击的选项的背景颜色

韦斯利·史密斯

我正在使用bootstrap-duallistbox

当前,当用户从任一框中单击一个选项时,该选项的背景变为蓝色一秒钟,然后该选项移动到另一个选择框中。

在此处输入图片说明

我想将颜色从蓝色更改为其他颜色。

这到底是什么状态?CSS应用option:activeoption:hoveroption:focus不干活,就选择此状态,并改变颜色。

我以为这可能有用,但也失败了。

select:-internal-list-box option:checked {
    color: #333 !important;
    background-color: #FFC894 !important;
}

也没有:

select:-internal-list-box option:selected  {
    color: #333 !important;
    background-color: #FFC894 !important;
}

select:-internal-list-box:focus  option:checked  {
    color: #333 !important;
    background-color: #FFC894 !important;
}

select:-internal-list-box:focus  option:selected  {
    color: #333 !important;
    background-color: #FFC894 !important;
}

select:-internal-list-box:focus option::selection  {
    color: #333 !important;
    background-color: #FFC894 !important;
}

.bootstrap-duallistbox-container:focus select option::selection {
    background: #ffb7b7 !important;
}

单击选项时如何更改显示的背景颜色?

这是一个显示问题jsFiddle

韦斯利·史密斯

事实证明,要做到这一点,你必须设置background的财产option而不是background-color像这样性质:

var demo1 = $('select').bootstrapDualListbox();
select option:hover, 
select option:focus, 
select option:active, 
select option:checked
{
    background: linear-gradient(#FFC894,#FFC894);
    background-color: #FFC894 !important; /* for IE */
}
<link href="https://rawgit.com/istvan-ujjmeszaros/bootstrap-duallistbox/master/src/bootstrap-duallistbox.css" rel="stylesheet"/>
<link href="http://netdna.bootstrapcdn.com/bootstrap/3.1.0/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://netdna.bootstrapcdn.com/bootstrap/3.1.0/js/bootstrap.min.js"></script>
<script src="https://rawgit.com/istvan-ujjmeszaros/bootstrap-duallistbox/master/src/jquery.bootstrap-duallistbox.js"></script>
<select multiple="multiple" size="10" name="" class="no_selection">
    <option value="option1">Option 1</option>
    <option value="option2">Option 2</option>
    <option value="option3" selected="selected">Option 3</option>
    <option value="option4">Option 4</option>
    <option value="option5">Option 5</option>
    <option value="option6" selected="selected">Option 6</option>
    <option value="option7">Option 7</option>
    <option value="option8">Option 8</option>
    <option value="option9">Option 9</option>
    <option value="option0">Option 10</option>
</select>


经过测试,可以在以下浏览器中运行:

视窗

  • 铬45.0.2454.101+
  • 火狐36.0.4+
  • IE 10以上

苹果电脑

  • 铬45.0.2454.101+
  • 火狐40.0.3+
  • Opera 30.0+

Ubuntu(感谢@davidkonrad)

  • 火狐

Safari确实看到了该属性,它在检查器中显示为处于活动状态,但是无论如何它都会忽略它。


我完全猜测为什么这行得通

使用CSS多背景状态:

使用CSS3,您可以将多个背景应用于元素。这些背景相互叠放,您提供的第一个背景位于顶部,背面提供了最后一个背景。

在我看来,用户代理蓝色背景仍然存在,但是添加的彩色背景background: linear-gradient(#FFC894,#FFC894);位于其上方。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章