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

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

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

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

通常是怎么做的?


当前回答

我建议两者都用。如果客户端不支持CSS,行和cols是必需的,也是有用的。但作为一名设计师,我会重写它们以获得我想要的尺寸。

推荐的方法是通过外部样式表。

textarea { 宽度:300 px; 身高:150 px; } textarea > < textarea > < /

其他回答

文本区域的大小可以通过cols和rows属性指定,甚至更好;通过CSS的高度和宽度属性。 所有主流浏览器都支持cols属性。 一个主要的区别是<TEXTAREA…>是一个容器标记:它有一个开始标记()。

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

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

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

在angularjs和angar7中测试

文本区域的一个主要特征是它们是可扩展的。在网页上,如果文本长度超过了你设置的空间(无论是使用行还是使用CSS),就会导致文本区域出现滚动条。这可能是一个问题,当用户决定打印,特别是“打印”到PDF -所以设置一个舒适的大最小高度打印文本区域的CSS条件规则:

@media print { 
textarea {
min-height: 900px;  
}
}

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).