如何将文本域设置为100%宽度和高度?

4个回答

2
这个方法可行。或者在你的代码中的textarea中添加display:block即可。

html, body {
  margin: 0;
  padding: 0;
  border: 0;
}
* {
box-sizing: border-box;
}

textarea {
  width: 100%;
  height: 100vh;
  display: block;
 }
<textarea placeholder="message"></textarea>


2
问题是由于垂直对齐,inline-block/inline 元素存在 常见的空格问题。如果您检查 Google 的 dev 工具,您会看到这个信息:

enter image description here

所以为了修复它,您只需要调整垂直对齐或使文本区域成为一个块级元素(就像其他答案中提供的一样):

html, body, textarea {
  margin: 0;
  padding: 0;
  border: 0;
  width: 100%;
  height: 100%;
}
textarea {
 vertical-align:top;
}
<textarea>Text goes here</textarea>


0

html, body {
  margin: 0;
  padding: 0;
  border: 0;
  width: 100%;
  height: 100%;
}
textarea {
  margin: 0;
  padding: 0;
  border: 0;
  width: 100%;
  height: 100%;
  display:block;
  resize:none;/*Add this if you dont want users to resize */
}
<textarea>Text goes here</textarea>


-1

只需为html和body标记删除宽度和高度即可。

稍后再感谢我。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接