每次我开发一个包含文本区域的新表单时,当我需要指定它的尺寸时,我都有以下困境:
使用CSS或使用文本区域的属性cols和行?
每种方法的优缺点是什么?
使用这些属性的语义是什么?
通常是怎么做的?
每次我开发一个包含文本区域的新表单时,当我需要指定它的尺寸时,我都有以下困境:
使用CSS或使用文本区域的属性cols和行?
每种方法的优缺点是什么?
使用这些属性的语义是什么?
通常是怎么做的?
当前回答
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).
其他回答
我通常不指定高度,但会指定宽度:……还有一排排和cols。
通常,在我的情况下,只需要宽度和行,textarea看起来很好,相对于其他elems。(如果有人不使用CSS, cols是一个备用方案,正如在其他答案中解释的那样。)
((同时指定行和高度感觉有点像复制数据吗?))
<textarea style="width:300px; height:150px;" ></textarea>
文本区域的一个主要特征是它们是可扩展的。在网页上,如果文本长度超过了你设置的空间(无论是使用行还是使用CSS),就会导致文本区域出现滚动条。这可能是一个问题,当用户决定打印,特别是“打印”到PDF -所以设置一个舒适的大最小高度打印文本区域的CSS条件规则:
@media print {
textarea {
min-height: 900px;
}
}
我建议两者都用。如果客户端不支持CSS,行和cols是必需的,也是有用的。但作为一名设计师,我会重写它们以获得我想要的尺寸。
推荐的方法是通过外部样式表。
textarea { 宽度:300 px; 身高:150 px; } textarea > < 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).