It is possible to expand a textarea only with CSS?

前端 未结 5 757
轮回少年
轮回少年 2020-11-29 01:48

I have a textarea with 200px of height, but when I pass that 200px with text I want to have the textarea expanded instead of keeping the 200px of height with a scroll bar.

5条回答
  •  误落风尘
    2020-11-29 02:31

    Here's a simple, pure php and html, solution, without need for js, to make the textarea fit to size. HTML:

        = $rows)   {
        $rows = $minrows;
       }
       // Return the number of rows
       return $rows;
       }
       ?> 
    

    `And this one is even shorter and better:

    function linecount($text, $cols, $minrows=1) {
        if ($text <= '') {return $minrows;}
        $text = wordwrap($text, $cols, PHP_EOL);
        $rows = substr_count( $text, PHP_EOL )+1;
        if ($minrows >= $rows) {$rows = $minrows;}
        return $rows;
    }
    ?>
    

提交回复
热议问题