Steven Lu
Steven Lu

Reputation: 43427

HTML: Can I mark/highlight a drop-down list menu item?

Say I've got a list. I want to let the user know that one of the indices was the one that was previously set. I would like it so that when the user opens the drop down menu he can see that one of the options is marked so it looks different from the rest.

Is there a facility for this? I won't bother with it if I have to hack up something ugly or re-implement the entire menu functionality to get this to work.

Upvotes: 0

Views: 5304

Answers (4)

Craig - Price Spin
Craig - Price Spin

Reputation: 41

Generally, this would be unnecessary as you would simply have the previously selected option pre-selected the next time the page loads when in state.

However, if you want to show select-list options in a specific colour, then you can essentially give each option individual css styles, shown in an example here.

Upvotes: 1

mikey
mikey

Reputation: 2072

Using the selected attribute on the option tag would be another solution. See

http://www.w3schools.com/tags/att_option_selected.asp

Upvotes: 0

acme
acme

Reputation: 14856

Are you talking about a simple <select>-Dropdown?

If so, it's pretty straightforward with CSS:

<select>
    <option style="background:yellow">yellow</option>
    <option style="background:red">red</option>
    <option style="background:blue">blue</option>
</select>

Of course CSS-Classes will work, too.

Upvotes: 0

dexter.ba
dexter.ba

Reputation: 292

If this is a element that has tags inside, you could try adding a specific class for option you want to highlight.

<option class="myoption"...

Then apply background color to this option through css.

.myoption {background-color: red;}

I think this will not work in IE 6 and 7, because you cannot apply styles for selects in these versions of browsers.

If you have < ul > and < li > elements for list, apply the same method decribed above.

Upvotes: 1

Related Questions