Solved

Can I change the font of select options?

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

Besides styling the entire <select>, can I style individual <option> tags?
0
Comment
Question by:cgipisani
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
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…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Suggested Courses

623 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