set dropdown list option with ellipses

后端 未结 3 1338
囚心锁ツ
囚心锁ツ 2021-01-17 03:18

I want to add ellipsis in the dropdown list options if I click the ellipsis able to see the full option values

for example, dropdown list looking li

3条回答
  •  遇见更好的自我
    2021-01-17 03:54

    Here is my solution for you problem.

    Its a workaround with the target to ellipse the select value and show the hole text when the options are shown. So the user can read the option values.

    $(document).ready(function () {
                $('div.viewport').text($('#example')[0].textContent);
                $('#example').change(function () {
                    $('div.viewport').text($("option:selected", this).text());
                });            
            });
     select, .container {
                width: 100px;
                z-index: 2;
                position: relative;
            }
    
            select {
                color: transparent;
                background: none;
            }
    
            .container {
                position: relative;
            }
    
            .viewport {
                position: absolute;
                width: 80%;
                height: 100%;
                z-index: 1;
                overflow: hidden;
                white-space: nowrap;
                -ms-text-overflow: ellipsis;
                -o-text-overflow: ellipsis;
                text-overflow: ellipsis;
                font-size: 14px;
                padding: 3px;
            }
    
            option {
                color: black;
            }
    
    

提交回复
热议问题