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

前端 未结 4 556
既然无缘
既然无缘 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:25

    Anno 2016 it is a bit more complicated. You need to wrap the in an "inline-block" that you made resizable:

    .resizable-input {
        /* make resizable */
        overflow-x: hidden;
        resize: horizontal;
        display: inline-block;
    
        /* no extra spaces */
        padding: 0;
        margin: 0;
        white-space: nowrap;
      
        /* default widths */
        width: 10em;
        min-width: 2em;
        max-width: 30em;
    }
    
    /* let  assume the size of the wrapper */
    .resizable-input > input {
        width: 100%;
        box-sizing: border-box;
        margin: 0;
    }
    
    /* add a visible handle */
    .resizable-input > span {
        display: inline-block;
        vertical-align: bottom;
        margin-left: -16px;
        width: 16px;
        height: 16px;
        background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAQAAAC1+jfqAAAAJUlEQVR4AcXJRwEAIBAAIPuXxgiOW3xZYzi1Q3Nqh+bUDk1yD9sQaUG/4ehuEAAAAABJRU5ErkJggg==");
        cursor: ew-resize;
    }

提交回复
热议问题