• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 316
  • Last Modified:

Font Color on SELECT options

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
Richard Korts
Asked:
Richard Korts
1 Solution
 
rgranlundCommented:
<option class="YOUR CLASS">

CSS:
.YOUR CLASS {
your attributes;
}
0
 
LZ1Commented:
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now