Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Putting images with options in a dropdown list

I was trying to insert images in a drop down list. I tried the following code but its not working. What is the best way to achieve this?

<select>   <option value="volvo"><IMG src="a.jpg"HEIGHT="15" WIDTH="15" BORDER="0"align="center">Volvo</option>   <option value="saab"><IMG src="b.jpg"HEIGHT="15" WIDTH="15" BORDER="0"align="center">Saab</option>   <option value="mercedes"><IMG src="c.jpg"HEIGHT="15" WIDTH="15" BORDER="0"align="center">Mercedes</option>   <option value="audi"><IMG src="d.jpg"HEIGHT="15" WIDTH="15" BORDER="0"align="center">Audi</option> </select> 
like image 655
Judy Avatar asked Feb 09 '11 03:02

Judy


People also ask

How can I insert images to select dropdown options?

Add <img> tag in dropdown content to insert image into dropdown list for each items.

Can we add image in option tag?

In HTML, <option> tags only display text, not images.

How do you customize a drop-down list?

On the worksheet where you applied the drop-down list, select a cell that has the drop-down list. Go to Data > Data Validation. On the Settings tab, click in the Source box, and then change your list items as needed. Each item should be separated by a comma, with no spaces in between like this: Yes,No,Maybe.


2 Answers

This code will work only in Firefox:

<select>     <option value="volvo" style="background-image:url(images/volvo.png);">Volvo</option>     <option value="saab"  style="background-image:url(images/saab.png);">Saab</option>     <option value="honda" style="background-image:url(images/honda.png);">Honda</option>     <option value="audi"  style="background-image:url(images/audi.png);">Audi</option> </select> 

Edit (April 2018):

Firefox does not support this anymore.

like image 175
JiBKas Avatar answered Sep 19 '22 14:09

JiBKas


You can't do that in plain HTML, but you can do it with jQuery:

JavaScript Image Dropdown

Are you tired with your old fashion dropdown? Try this new one. Image combo box. You can add an icon with each option. It works with your existing "select" element or you can create by JSON object.

like image 45
Nick Avatar answered Sep 19 '22 14:09

Nick