Solved

Font Color on SELECT options

Posted on 2012-03-22
2
312 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
[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 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Flex Messes  With Horizontal Positioning 2 25
Anyone familiar with PhotoSwipe? 3 19
Position Absolute Goes Beyond Parent 11 21
Session on Html 8 42
This article discusses four methods for overlaying images in a container on a web page
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

726 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