I have a drop down list. I want to add images along with it. I tried adding img
tag inside tha option
tag... But still the images are not getting displayed.
How do I do it using option
tag?
It's not possible, as <option>
only supports text.
You may have to roll your own drop-down control using complex HTML/CSS/JavaScript. How to do it may or may not be within the scope of your question.
Alternatively, you may use a non-repeating background-image
and apply some padding on the text to achieve a similar effect. But if each <option>
is to have a unique image, your code is going to be polluted with a style
attribute for every single <option>
. If you don't mind that, it's fine. Otherwise, roll your own somehow.
精彩评论