How can I create an editable dropdownlist in HTML?

前端 未结 11 1082
终归单人心
终归单人心 2020-11-29 01:51

I\'d like to create a text field with a dropdown list that lets the user choose some predefined values. The user should also be able to type a new value or select a predefin

11条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-29 02:18

    HTML doesn't have a built-in editable dropdown list or combobox, but I implemented a mostly-CSS solution in an article.

    You can see a full demo here but in summary, write HTML like this:

    
      
      
      
    
    

    And use CSS like this to style it (this is designed for both comboboxes, which have a down-arrow ▾ button, and dropdown menus which open when clicked and may be styled differently):

    /* ------------------------------------------ */
    /* ----- combobox / dropdown list styling     */
    /* ------------------------------------------ */
    .combobox {
      /* Border slightly darker than Chrome's 
                            
        
    提交评论

提交回复
热议问题