How to include images for <selection> <option>?

I have a list of countries displayed inside select-tag option tags, what I would like to do is to indicate the country flag next to its name.

I tried to insert img tags into select-option tags, this will not work.

Please, help

thank

+3
source share
6 answers

In Firefox, you can use a background image, but at least IE6 and IE7 do not support this. There is no pure html / css solution that will work consistently in all OS and browsers.

, , , Javascript , , . , Javascript, . .

, Javascript, ​​ Mootools , MavSelectBox

+1

. . - - . - onchange , .

, option, - , , background-position-x background-position-y.

0

.

( "Utrustning" ) . , div, html, .

0

Try setting the images using backgroundCSS (either through styleor class). You will also need paddingor something similar so that the text does not overlap with the flags.

-2
source

try it.

CSS

<style>
  .test1 { background:url(../images/folder-blue.gif) no-repeat; padding-left:16px;}
</style>

<select>
    <option class="test1">Test 1</option>
    <option class="test2">Test 2</option>
    <option class="test3">Test 3</option>
</select>
-2
source
<select>
    <option style="background-image: url('images/us.gif') no-repeat left center; padding-left: 20px;">USA</option>
    <option style="background-image: url('images/fr.gif') no-repeat left center; padding-left: 20px;">France</option>
</select>

Alternatively, you can do this using <LI>HTML / CSS and a hidden form field.

-2
source

Source: https://habr.com/ru/post/1741860/


All Articles