Using Div instead of textarea in HTML to realize input box height change with input content

Source: Internet
Author: User

Requirements in the project: The message column input height changes, more than 1 lines, automatic stretching, more than 4 lines, no longer stretch. The main idea is to use the minimum height and maximum height, plus overflow to achieve, to the maximum height, the text will not overflow but hidden. Depending on the size of the font in the text box, the height needs to be adjusted appropriately.

Code:

<id= "Leave-message-textarea"  contenteditable= "true"  Data-text= "input message"></div>
  #leave-message-textarea  { width : Span style= "color: #0000ff;" > 100% ;  Min-height : 20px ;  Max-height : 70px ;  outline :  0 ;  border :  1px solid #000 ;  Font-size :  13px ;  Overflow-x :  hidden ;  overflow-y :  auto ; -webkit-user-modify : ;} 

Where Div's placeholder effect is implemented with the Data-text property, the CSS code is as follows:

[Contenteditable=true]:empty:not (: Focus): Before {    content:attr (Data-text);}

Using Div instead of textarea in HTML to realize input box height change with input content

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.