开发者

Adding images with option tag [duplicate]

开发者 https://www.devze.com 2023-02-22 22:29 出处:网络
This question already has answers here: How to add images in select list? (15 answers) Closed 6 years ago.
This question already has answers here: How to add images in select list? (15 answers) Closed 6 years ago. 开发者_运维问答

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.

0

精彩评论

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