Can I colour backgrounds of selected items in HTML select options with CSS only?

后端 未结 4 2071
慢半拍i
慢半拍i 2020-11-30 12:10

I\'ve searched around a lot and see people suggesting that:

::-moz-selection {background: red;}
::selection {background: red; }

..works for

4条回答
  •  攒了一身酷
    2020-11-30 13:14

    I found this because I was having the same problem, I did find an odd solution that seems to work atleast with chrome and maybe others. The solution was to use an attribute selector. This seemed to work with chrome, I tested it in the js fiddle. A side note that the box did not immediately change color to background red but once I selected another option I could clearly see that it had indeed turned red. You can check it out in the jsfiddle listed above.

    http://jsfiddle.net/vzDvK/1/

    #dropdowns option[selected] {
        background: red;
    }
    

提交回复
热议问题