Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Text color in a drop down menu

Status
Not open for further replies.

MJB3K

Programmer
Jul 16, 2004
524
GB
Hi, how can you change the color of the text in a drop down menu?
Code:
<option value="cupGroups.php?g=<?php echo $gid; ?>&group=<?php echo $groupID; ?>">&nbsp;<?php echo $groupName; ?> [COLOR=red](<?php echo $amnt; ?>/12)[/color]</option>
I would like to be able to change the text in red to red or green if neccissary (il do this in php).

Any ideas??

Regards,

Martin

Computing Help And Info:
 
You can't do that in my experience. It may be possible in a specific browser, but certainly not cross-browser or cross-platform.

Cheers,
Jeff

[tt]Jeff's Page [/tt][tt]@[/tt][tt] Code Couch
[/tt]
 
When experimenting, it's easier to get rid of the php and just write snippets of html that you can play with. I tried this:
Code:
<select>
<option>This is <span style="color: red">Red</span></option>
</select>
However, it doesn't work in IE or FF. It may do in some Mac-based browsers.

Most browsers will let you change the colour of a whole <option>, but not (it seems) just a part of it.

-- Chris Hunt
Webmaster & Tragedian
Extra Connections Ltd
 
yea i was afraid of that. You should be able to change any part of the text to what you want.

Regards,

Martin

Computing Help And Info:
 
Greetings all!

You can accomplish some of this using styles:
Code:
<SELECT ID="test" SIZE=4>
   <OPTION style="background-color: #CCCC99;color: #999999">Opt 1</OPTION>
   <OPTION style="background-color: #C0C0C0;color: #00FF00">Opt 2</OPTION>
   <OPTION style="background-color: #C0C0C0;">Opt 3</OPTION>
   <OPTION style="background-color: #C0C0C0;">Opt 4</OPTION>
</SELECT>

Good luck!

He who has knowledge spares his words, and a man of understanding is of a calm spirit. Even a fool is counted wise when he holds his peace; when he shuts his lips, he is considered perceptive. - King Solomon
 
BillyRayPreachersSon, how is that a ridiculus statement?

What if you wanted some of the text a different color like i do.... ??

Regards,

Martin

Computing Help And Info:
 
I was talking about your statement, not your needs.

The fact you want to change different parts of your text to different colours is not ridiculous in the least. It's your requirement, and that's fair enough.

However, to say that you should be able to arbitrarily change the colour of portions of text in a control that the browser has little-to-no control over (and at that, a control that would differ from browser to browser, and OS to OS) is ridiculous. Why should you be able to?

Dan


[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Am I missing something here?
Could we not create a CSS class for the new colour and just wrap the section of text in a "<span>" using that class?


Trojan.
 
Wow, I just assumed that the style would work. Obviously it doesn't.
You learn something new every day (as they say!).
Do you know what the CSS2 spec says about this? Is it normal to ignore the styling?



Trojan.
 
I think the problem is that browsers rely on the host operating system to provide forms controls to them, that's why they look so different on different platforms. Nonetheless this is generally a good thing - users get forms presented in a way that they are used to - but it can cause problems like this. Windows drop-down controls can (apparently) only handle one colour per line, so that's what you get.

However, there is a way to totally change the appearance of <select>s, with some clever use of javascript (those with javascript switched off get the ordinary <select> intead). Take a look at the two "<select> something new" articles here: you may be able to adapt it to your needs.

-- Chris Hunt
Webmaster & Tragedian
Extra Connections Ltd
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top