If you want to style each one of the option tags.. use the css attribute selector:
select option { margin: 40px; background: rgba(0, 0, 0, 0.3); color: #fff; text-shadow: 0 1px 0 rgba(0, 0, 0, 0.4); } select option[value="1"] { /* value not val */ background: rgba(100, 100, 100, 0.3); } select option[value="2"] { /* value not val */ background: rgba(200, 200, 200, 0.3); } /* ... */
回答2:
I don't know if you've considered it or not but if your application is based on coloring various groupings of items you should probably use the tag coupled with a class for further referencing. For example:
and then in the head of your document write the css like this:
Similar to some of the answers, but not really stated, is to add a class to the actual option tag and use css classes...this is currently working for me without issue on IE (see above ss).
However a warning is attached to that approach. These types of menus work very differently on mobile platforms because native elements aren't used. They can have annoying quirks on desktop as well. My advice is 1) don't write your own and 2) find a library that's been really well tested.
回答9:
Here it goes what I've learned about the subject!
The CSS 2 specification did not address the problem of how form elements should be presented to users period!
Eventually, you will never find any technical article from w3c or other addressed to this topic. Styling form elements in particular select boxes is not fully supported however, you can drive around... with some effort!