css里面li标签怎么加图片_如何使用CSS将背景图片放入选择选项标签

I have a country dropdown list receiving from json response, and want to add respective country flag icons (getting the images as well from json reponse) next to the country names.

I have tried different jQuery and bootstrap plugins for that but what they are doing is ruining my previous select box styling and are adding their own ones dynamically.

I want to achieve this using CSS only.

Code tried so far :

foreach ($countries as $countriesList) {

echo '' . $countriesList['name'] . '';

}

?>

CSS:

select.icon-menu option {

background-repeat:no-repeat;

background-position:bottom left;

padding-left:30px;

}

But not getting any results, i am stucked pls help

解决方案

You can't give an option tag a background-image.

One solution will be to create your own "select" component.

  • option1
  • option2>

..

then you give some css to look like a select input.

And some javascript to handle showing and hiding "li" elements

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值