Printable Version of Topic

Click here to view this topic in its original format

HTMLHelp Forums _ Cascading Style Sheets _ How to style an option in a dropdown

Posted by: Nalini Oct 19 2016, 10:42 AM

Hello,

I want to style a particular option which has a value of -1 in a dropdown. How should I target it? Please advice.

Posted by: Christian J Oct 19 2016, 11:46 AM

If the OPTION element's VALUE attribute is specified you might use an attribute selector, like this:

CODE
option[value="-1"] {color: red;}

<select>
<option value="1">foo</option>
<option value="0">bar</option>
<option value="-1">baz</option>
</select>

If the VALUE attribute is not specified (a value can be specified with the OPTION's content as well) the above won't work, though.

Posted by: Nalini Oct 19 2016, 12:20 PM

QUOTE(Christian J @ Oct 19 2016, 12:46 PM) *

If the OPTION element's VALUE attribute is specified you might use an attribute selector, like this:

CODE
option[value="-1"] {color: red;}

<select>
<option value="1">foo</option>
<option value="0">bar</option>
<option value="-1">baz</option>
</select>

If the VALUE attribute is not specified (a value can be specified with the OPTION's content as well) the above won't work, though.

Thank you so much! Worked like a charm.

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)