How to change font-family of drop down's list item?

前端 未结 7 650
长情又很酷
长情又很酷 2020-11-29 07:59

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.

相关标签:
7条回答
  • 2020-11-29 08:59

    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:

    <SELECT style='font-size: 10px; font-family: "Verdana", Sans-Serif;' name='???????'>
    <?php echo $your_variable_containing_dropdown_content; ?>
    </SELECT>
    

    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.

    0 讨论(0)
提交回复
热议问题