Solved

Font Color on SELECT options

Posted on 2012-03-22
2
309 Views
Last Modified: 2012-06-21
I want to have a different font color on some of the <option> of a <select>

The <option> list will be built dynamically via php.

What is the right syntax (css) for font color on the <option> element?
0
Comment
Question by:Richard Korts
2 Comments
 
LVL 7

Accepted Solution

by:
rgranlund earned 500 total points
ID: 37753039
<option class="YOUR CLASS">

CSS:
.YOUR CLASS {
your attributes;
}
0
 
LVL 30

Expert Comment

by:LZ1
ID: 37753120
If it's built dynamically by PHP, you can't assign a class to a specific option then.  

What you could do(depending on which browser your trying to target), is use the nth-child in CSS.

Try the code below: (Remember this will not work in IE 8)

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Untitled Document</title>
<style>
	select option:nth-child(odd){color:#36f;}
</style>

</head>


<body>
<select>
	<option>Option 1 </option>
	<option>Option 1 </option>
	<option>Option 1 </option>
	<option>Option 1 </option>
	<option>Option 1 </option>
	<option>Option 1 </option>
	<option>Option 1 </option>
	<option>Option 1 </option>
</select>
</body>
</html>

Open in new window

0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Suggested Solutions

Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
Find out what you should include to make the best professional email signature for your organization.
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
In this tutorial viewers will learn how to embed custom externally-hosted Google Fonts using the Google Font API in CSS Go to the Google Fonts website at google.com/fonts: Browse or search based on font properties or name to find a suitable font for…

803 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