开发者

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.


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.


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.


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.


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

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜