Angular select with images

后端 未结 5 1357
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-15 13:44

THE SITUATION:

I need to insert flags inside the language select. I have searched in Google and StackOverflow but the solutions founded are not work

5条回答
  •  我在风中等你
    2021-01-15 14:14

    this is impossible with a native select element,

    therfore, you need to design a selectbox using other html elements & css,

    try this out:

    var app = angular.module('app',[]);
    
    //app.directive('appDirective', function() {});
    //app.factory('appService', function() {});
    
    function AppCtrl($scope) {
    	$scope.obj={language_selected : {'name':'Choose a language'}};
        $scope.language_list = [{'name': 'english', 'url': 'https://raw.githubusercontent.com/stevenrskelton/flag-icon/master/png/16/country-4x3/gb.png'},{'name': 'italian', 'url': 'https://raw.githubusercontent.com/stevenrskelton/flag-icon/master/png/16/country-4x3/it.png'}];
        
    }
    .select_list{
        background-color: #fff;
        border: 1px solid #b3b3b3;
        cursor: pointer;
        height: 21px;
        line-height: 21px;
        padding: 3px 5px;
        position: relative;
        vertical-align: middle;
        width: 250px;
    }
    .select_list:after{
        content:"▼";
        position:absolute;
        right:3px;
        color:#b3b3b3;
    }
    .select_list > .options{
        display:none;
        position:absolute;
        top:100%;
        left:-1px;
        width:100%;
        border:1px solid #666;
        padding:0;
        margin:0;
    }
    
    .select_list.active > .options{
        display:block;
    }
    
    .select_list > span, .select_list > .options li {
        background-position: 5px center;
        background-repeat: no-repeat;
        padding-left: 30px;
        list-style:none;
    }
    
    .select_list > .options li:hover {
        background-color:#eee;
    }
    
    
    {{obj.language_selected.name}}
    • {{language.name}}

提交回复
热议问题