每次我开发一个包含文本区域的新表单时,当我需要指定它的尺寸时,我都有以下困境:

使用CSS或使用文本区域的属性cols和行?

每种方法的优缺点是什么?

使用这些属性的语义是什么?

通常是怎么做的?


当前回答

 <textarea style="width:300px; height:150px;" ></textarea>

其他回答

The answer is "yes". That is, you should use both. Without rows and cols (and there are default values even if you don't use them explicitly) the textarea is unusably small if CSS is disabled or overriden by a user stylesheet. Always keep accessibility concerns in mind. That being said, if your stylesheet is allowed to control the appearance of the textarea, you will generally wind up with something that looks a whole lot better, fits into the overall page design well, and that can resize to keep up with user input (within the limits of good taste, of course).

对于文本区域,我们可以使用下面的css来固定大小

    <textarea  class="form-control" style=" min-width:500px; max-width:100%;min-height:50px;height:100%;width:100%;" ></textarea>

在angularjs和angar7中测试

CSS


input
{
    width: 300px;
    height: 40px;
} 

HTML


<textarea rows="4" cols="50">HELLO</textarea>

根据w3c, cols和rows都是textarea的必需属性。行和Cols是将适合文本区域的字符数,而不是像素或其他潜在的任意值。顺着row /cols走。

HTML行和cols没有响应!

我用CSS定义了大小。提示:如果你为手机定义了一个小尺寸,可以考虑使用textarea:focus {};

在这里添加一些额外的空间,它只会在用户真正想要写一些东西的时候展开