How to style a select tag's option element?

前端 未结 6 1556
渐次进展
渐次进展 2020-11-22 11:03

I\'m trying to set the style of an option in a select dropdown menu in Google Chrome. It works in all browsers except IE9 and Chrome.

6条回答
  •  眼角桃花
    2020-11-22 11:20

    I actually discovered something recently that seems to work for styling individual elements within Chrome, Firefox, and IE using pure CSS.

    Maybe, try the following:

    HTML:

    
    

    CSS:

    select {
        background-color:#000;
        color: #FFF;
    }
    
    select * {
        background-color:#000;
        color:#FFF;
    }
    
    select *.red { /* This, miraculously, styles the '' elements. */
        background-color:#F00;
        color:#FFF;
    }
    
    select *.white {
        background-color:#FFF;
        color:#000;
    }
    
    select *.blue {
        background-color:#06F;
        color:#FFF;
    }
    

    Strange what throwing caution to the wind does. It doesn't seem to support the :active :hover :focus :link :visited :after :before, though.

    Example on JSFiddle: http://jsfiddle.net/Xd7TJ/2/

提交回复
热议问题