我有选择标签,需要根据选择更改选项的背景图像。我正在使用下面的样式,这种风格适用于Chrome但不适用于IE 11.不确定我需要做些什么改变才能使它在IE 11上运行?
option:checked
{
background-image: url("SelectBlue.png");
color: white;
}
以下完整的HTML代码
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>change demo</title>
<style>
div {
color: red;
}
</style>
<style type="text/css">
select::-ms-expand
{
display:none;
}
.ListBox{
background-color: transparent;
font-family: verdana;
font-size: 8pt;
font-weight: bold;
color: black;
vertical-align:middle;
height:400px;
width:300px;
}
option:checked {
background-image: url("DataGridSelectBlue.png");
color: white;
}
</style>
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
<input id="hid" type="hidden">
<select id="sweets" name="sweets" multiple="multiple" class="ListBox">
<option value="a">Chocolate</option>
<option value="b" selected="selected">Candy</option>
<option value="c">Taffy</option>
<option value="d" selected="selected">Caramel</option>
<option value="e">Fudge</option>
<option value="f"> Cookie</option>
</select>
<select name="food" multiple="multiple" class="ListBox">
<option>Idly</option>
<option selected="selected">Sambar</option>
<option>Dosa</option>
<option selected="selected">Bisibele bhath</option>
<option>chutney</option>
<option>upma</option>
</select>
<div></div>
</body>
</html>
答案 0 :(得分:0)
经过深入研究后
根据MDN:已检查的CSS伪类选择器(基本功能)与IE11兼容:
来源:https://developer.mozilla.org/en-US/docs/Web/CSS/:checked
如果是这样,它可能无效的原因是该属性&#39; background-image&#39;并不完全与浏览器兼容。
我使用chrome并创建了以下codepen(基于您的代码) - 您可以在多个浏览器上测试它以查看支持哪个属性:
option:checked {
background-color: green; /*Won't apply*/
color: green; /*Won't apply*/
border:1px solid green; /*Will apply (at least on chrome)*/
background-image:url('http://www.bostonscientific.com/content/dam/bostonscientific/utility-icons/icon_Phone.png'); /*Will apply (at least on chrome)*/
}