How to make text input box resizable (like textarea) by dragging its right-bottom corner using jQuery?

前端 未结 4 505
既然无缘
既然无缘 2021-02-05 16:24

I would like to have (preferrably in jQuery) regular text input box which can be clicked and dragged by its right-bottom corner (e.g. like textareas have in Chrome) and resized

4条回答
  •  误落风尘
    2021-02-05 17:26

    I made a variation on kay's answer, using the pseudo element ::after instead of a second span. in short:

    .resizable-input { ... }
    .resizable-input > input { ... }
    .resizable-input::after { ... }
    /* the last one used to be .resizable-input > span { ... } */
    

    with html just:

    
    

    See full code and see it in action here: https://jsfiddle.net/ElMoonLite/qh703tbe/

    Also added input { padding-right: 0.5em; } so you can still resize it if it's value is full of text.


    Still seems to work in 2019 in Chrome.
    In Edge resize does not seem to work (but otherwise looks ok (graceful degradation)). Haven't tested other browsers yet.

提交回复
热议问题