I have a drop-down that lists font families. Like Tahoma, Arial, Verdana, etc. I want to change the font-family of each drop-down item according to the value it represents. Just like Photoshop does it.
I changed the CSS for each drop-down item but it only works on FireFox. It doesn't work on any other browser.
I don't want to use any jQuery plugin.
You can do something like this
What you can do in CSS is what you described: setting
font-family
onoption
elements, and this has limited browser support. Browsers may implementselect
elements using routines that are partly or completely immune to CSS.The workaround is to use something else than a
select
element, such as a set of radio buttons, but it will of course be rendered differently from a dropdown menu. Then you can use e.g.You can set fonts for an HTML drop-down in the following way:
1. Build your list of options that will be displayed in your dropdown, but don't apply any styling/classes to any of those options. In PHP I would store my list of options to a variable and then use that variable to add options to my dropdown which I'll show below.
2. When you want to actually insert the dropdown into the page, use the SELECT tag and put some CSS styling inside that tag as I've shown below:
That works 100% fine for me on the website I'm currently working. This is just the styling that I've used in my page, but it can be whatever you need it to be.
Try this:
This should Give you an Idea as to ho to accomplish this:
JSFIDDLE
That's because the
select
elements children (option
s) aren't really stylable and firefox seems to be the only browser to ignore that part of the spec.The workaround is to replace your
select
element with a custom widget that uses only stylable elements and perhaps a little javascript for the interactivity. like what's done here:http://jsfiddle.net/sidonaldson/jL7uU/or http://jsfiddle.net/theredhead/4PQzp/