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

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

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

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

通常是怎么做的?


当前回答

如果你不是每次都使用line-height:'..';属性控制textarea的高度,width属性控制textarea的宽度。

或者你可以通过下面的css来使用font-size:

#sbr {
  font-size: 16px;
  line-height:1.4;
  width:100%;
}

其他回答

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

HTML行和cols没有响应!

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

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

CSS


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

HTML


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

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

如果你不是每次都使用line-height:'..';属性控制textarea的高度,width属性控制textarea的宽度。

或者你可以通过下面的css来使用font-size:

#sbr {
  font-size: 16px;
  line-height:1.4;
  width:100%;
}