Solved

Font Color on SELECT options

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…

910 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now