开发者

How to add images in select list?

开发者 https://www.devze.com 2023-01-01 21:36 出处:网络
I have a select list of genders. Code: <select> <option>male</option> <option>female</option>

I have a select list of genders.

Code:

<select>
<option>male</option>
<option>female</option>
<option>oth开发者_Go百科ers</option>
</select>  

I want to use an image in drop down list as drop-down-icon.jpeg.

I want to add a button in place of drop down icon.

How to do that?


In Firefox you can just add background image to option:

<select>
  <option style="background-image:url(male.png);">male</option>
  <option style="background-image:url(female.png);">female</option>
  <option style="background-image:url(others.png);">others</option>
</select> 

Better yet, you can separate HTML and CSS like that

HTML

<select id="gender">
  <option>male</option>
  <option>female</option>
  <option>others</option>
</select>  

CSS

select#gender option[value="male"]   { background-image:url(male.png);   }
select#gender option[value="female"] { background-image:url(female.png); }
select#gender option[value="others"] { background-image:url(others.png); }

In other browsers the only way of doing that would be using some JS widget library, like for example jQuery UI, e.g. using Selectable.

From jQuery UI 1.11, Selectmenu widget is available, which is very close to what you want.


With countries, languages or currency you may use emojis.

Works with pretty much every browser/OS that supports the use of emojis.

select {
 height: 50px;
 line-height: 50px;
 font-size: 12pt;
}
<select name="countries">
    <option value="NL">
0

精彩评论

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