Is there anyway to have a textarea “autofit” height based on the content at page load?

前端 未结 13 1769
借酒劲吻你
借酒劲吻你 2020-12-15 17:46

Is there anyway through CSS or Javascript set the height of the textarea based on the content? I have a hardcoded height in my CSS but i wanted it to default so there is no

13条回答
  •  难免孤独
    2020-12-15 18:17

    If you dont mind a scollbar inside the text area you can use

    $(document).ready(function(){
        tx = $('#textarea')
        tx.height(tx.prop('scrollHeight'));
    
    })
    

    and here is a Fiddle

    another Fiddle this has min and max-width set.

    but with plug-ins like auto-size

    the height of the text box increases with input.

    or you can try this plug-in

提交回复
热议问题