Help - Search - Members - Calendar
Full Version: How to style an option in a dropdown
HTMLHelp Forums > Web Authoring > Cascading Style Sheets
Nalini
Hello,

I want to style a particular option which has a value of -1 in a dropdown. How should I target it? Please advice.
Christian J
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.
Nalini
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.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2024 Invision Power Services, Inc.