4 Replies - 16205 Views - Last Post: 02 March 2009 - 11:15 AM

#1 kummu4help  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 4
  • View blog
  • Posts: 245
  • Joined: 05-August 08

how to change the text color in option tag

Posted 26 February 2009 - 11:06 PM

can i use like this
<select name="test" >
<option value="1">option</option>
<option value="2"><p style="background-color:#FF0055;">again</p></option>
</select>



i don't want to use style in the option tag.
because i am getting the option text from database.
so i want to apply style to the text only.

because i have no chance to use styles in the option tag. that is strictly avoided by my existing code.i am allowed to do changes to the text part only.
i am not allowed to touch option tag or select tag.

i tried like this also

<option value="2"><font color=red>again</font></option>


any help pls...

Is This A Good Question/Topic? 1

Replies To: how to change the text color in option tag

#2 no2pencil  Icon User is offline

  • Dic Head
  • member icon

Reputation: 5163
  • View blog
  • Posts: 26,835
  • Joined: 10-May 07

Re: how to change the text color in option tag

Posted 26 February 2009 - 11:10 PM

Use css, & just point the individual options to the class type/name.
<html>
<head>
 <style>
  .red {
	  color: red;
	  font-size: 2em;
  }
  .blue {
	  color: blue;
	  font-weight: bold;
  }
 </style>
</head>
<body>
 <select multiple size='5'>
  <option>Option #1</option>
  <option class="red">Option #2</option>
  <option>Option #3</option>
  <option class="blue">Option #4</option>
 </select>
</body>
</html> 


Was This Post Helpful? 0
  • +
  • -

#3 kummu4help  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 4
  • View blog
  • Posts: 245
  • Joined: 05-August 08

Re: how to change the text color in option tag

Posted 26 February 2009 - 11:16 PM

thanks for reply no2pencil,

but i am not allowed to use styles in the option tag.
i can do whatever for the text only.

i am blocked like that

so can u tell me any way so that i can change the color of text in the option tag
Was This Post Helpful? 0
  • +
  • -

#4 dom96  Icon User is offline

  • D.I.C Regular

Reputation: 4
  • View blog
  • Posts: 256
  • Joined: 29-December 08

Re: how to change the text color in option tag

Posted 02 March 2009 - 10:39 AM

Change the code you have..
<select name="test" >
<option value="1">option</option>
<option value="2"><p style="background-color:#FF0055;">again</p></option>
</select>


To this
<select name="test" >
<option value="1">option</option>
<option value="2"><p style="color:#FF0055;">again</p></option>
</select>


does that help ?
Was This Post Helpful? 0
  • +
  • -

#5 cbrickhouse  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 57
  • Joined: 01-March 09

Re: how to change the text color in option tag

Posted 02 March 2009 - 11:15 AM

why would you use a p tag inside an option tag?

change your code to this

<select>
<option style="color:whatever_color; background-color: different_color">text</option>
<option style="color:whatever_color1; background-color: different_color1">text</option>
</select>



i would use a stylesheet instead of inline styles but if that's the only way you can do it then go with that.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1