更改文本区域的大小 [英] Change size of textarea

查看:24
本文介绍了更改文本区域的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前有一个像这样的 textarea:

I currently have a textarea like this:

<textarea matInput rows="5" cols="40" placeholder="text"></textarea>

然而,它总是相同的大小.

However, it is always the same size.

知道如何改变 textarea 的大小吗?

Any idea on how to change the size of the textarea?

推荐答案

取决于您的意思:

然而,它总是相同的大小.

However, it is always the same size.

有两种选择.

目前,只有 rows 影响材质 textarea 高度,cols 不会改变其宽度.

Currently, only rows affects the Material textarea height, cols doesn't change its width.

因此,为了增加宽度,我们必须在包含我们的 textareamat-form-field 上使用 CSS width 属性:

Therefore for increasing width, we have to use the CSS width property on a mat-form-field containing our textarea:

<mat-form-field style="width: 300px;">
    <textarea matInput rows="5" cols="40" placeholder="text"></textarea>
</mat-form-field>

选项 2(适合 textarea 内容的动态大小):

在材料 6 中,添加了 CdkTextareaAutosize 指令.

OPTION 2 (DYNAMIC size to fit textarea content):

In Material 6, CdkTextareaAutosize directive was added.

来自官方文档:

cdkTextareaAutosize 指令可以应用于任何