how to expand a text area when click on

后端 未结 9 1292
感情败类
感情败类 2021-02-02 10:17

Im working on a small project which has a textarea and i need help in making the text area expand on mouse click like that of twitter and facebook. the textarea should look lik

9条回答
  •  深忆病人
    2021-02-02 10:33

    You can do this with CSS only using position: absolute, which will make it float over other elements, and the :focus selector, which will be applied only when the element have the focus. First you need to reserve the textarea size enclosing it in an element:

    div.textarea { height: 50px; width: 400px; }

    Then style the unfocused textarea

    textarea {
       position: absolute;
       height: 50px;
       width: 400px;
       transition: all 200ms;
    }
    

    And finally the focused one

    textarea:focus {
       z-index: 1001;
       min-height:250px;
    }
    

    Fiddle: http://jsfiddle.net/7v60su9e/

提交回复
热议问题