使用chosen.js,我该如何将图片添加到下拉选项中?

7
使用chosen.js,我该如何在下拉菜单项中添加图片?
2个回答

7
通过在选定的列表项上设置background-image
.chzn-results li {
    background: url('path/to/img.png') no-repeat 3px center;
    padding-left: 12px;
}

根据需要调整像素计数。


解决方案:CSS规则应该是background而不是background-image - Richard

2
为了补充 Joseph 的答案(我不能在他的答案中添加评论),自从某个未知版本以来,该类已经发生了改变: 以下是 v1.0.0 中正确的 CSS:
li.active-result {
    background: url('path/to/img.png') no-repeat 3px center;
    text-indent:2em;
}

谢谢你,Joseph!

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接