Solved

Can I change the font of select options?

Posted on 2006-07-11
6
5,240 Views
Last Modified: 2013-12-03

Besides styling the entire <select>, can I style individual <option> tags?
0
Comment
Question by:cgipisani
  • 2
6 Comments
 
LVL 15

Expert Comment

by:Daydreams
ID: 17088134
Hi cgipisani,

You can style the individual option tags. Take a look here:

http://www.codefoot.com/javascript/script_dropdown_formatting.html
0
 

Author Comment

by:cgipisani
ID: 17089750
I should have been more specific.  Can I style the font in the <option> tags?
0
 
LVL 15

Accepted Solution

by:
Daydreams earned 63 total points
ID: 17092876
The styling of the option tag seems to work with Firefox, but not IE:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title></title>
<style type="text/css">
select.Menu{
  font-family: Verdana,sans serif;
  font-size:   14pt;
  font-weight: bold;
  font-style:  normal;    
}

option.MenuOne{
  color:#FFFFFF; font-family:"times new roman";
  background-color:#FF0000;
}
option.MenuTwo{font-family:arial;
  color:#FFFF00;
  background-color:#0000FF;
}
option.MenuThree{font-family:"lucida calligraphy";
  color:#123456;
  background-color:#FEDCBA;
}

</style>

</head>
<body>
<form>
<select class="Menu" size="1">
<option class="MenuOne">Item One</option>
<option class="MenuOne">Item Two</option>
<option class="MenuOne">Item Three</option>
<option class="MenuTwo">Item Four</option>
<option class="MenuTwo">Item Five</option>
<option class="MenuTwo">Item Six</option>
<option class="MenuThree">Item Seven</option>
<option class="MenuThree">Item Eight</option>
<option class="MenuThree">Item Nine</option>
</select>
</form>
</body>
</html>

Other experts may yet comment..
0
 
LVL 29

Assisted Solution

by:rdivilbiss
rdivilbiss earned 62 total points
ID: 17099367
Daydreams' example code styles the options in Firefox 1.5.0.4 and IE 6.0.2900.2180.xpsp_sp2_gdr.050301-1519.

It does not work in Opera 8.54 rev 7730.

The W3C recommendation for the <option> tag does include the STYLE attribute, implying you may style individual option elements, however you are up against the vagarities of the various browser implementations.  See:>http://www.w3.org/TR/REC-html40/interact/forms.html#edef-OPTION

If you choose to do this, you will need to accept the fact that many user agents will ignore the style for the option elements.

Regards,
Rod



0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Owl Carousel 6 203
Does a Google search find images with the word being searched? 11 74
Form submit issue 11 85
Problem to file 3 74
Article by: Matthew
I am a very big proponent of technology compliance standards and strive to meet such criteria in all of my work. That includes my site, which is 100% XHTML 1.0 compliant as determined by the World Wide Web Consortium. https://www.matthewstevenkel…
Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question