Set width of dropdown element in HTML select dropdown options

后端 未结 7 1112
醉话见心
醉话见心 2020-11-27 21:36

I am working on a website that involves automatically populating a select box using a PHP script. This all works fine except the problem is that what I am using to populate

7条回答
  •  清酒与你
    2020-11-27 22:16

    I find the best way to handle long dropdown boxes is to put it inside a fixed width div container and use width:auto on the select tag. Most browsers will contain the dropdown within the div, but when you click on it, it will expand to display the full option value. It does not work with IE explorer, but there is a fix (like is always needed with IE). Your code would look something like this.

    HTML

    
    

    CSS

    div.dropdown_container {
        width:10px;
    }
    
    select.my_dropdown {
        width:auto;
    }
    
    /*IE FIX */
    select#my_dropdown {
        width:100%;
    }
    
    select:focus#my_dropdown {
        width:auto\9;
    }
    

提交回复
热议问题