html中,textarea中内容如何垂直居中

html中,textarea中内容如何垂直居中显示?

阅读 35.6k
6 个回答

说明一下,上一个答主回答的“text-align: center”是文本水平居中
不是垂直居中!!!
你可以设置:“height 和 line-height”(两个值一样);
还有一种方法:

display: table-cell; vertical-align: middle
<!DOCTYPE html>
<html>
<head>
    <title></title>
    <style type="text/css">
        textarea{
            text-align:center;
        }
    </style>
</head>
<body>
<textarea rows="10" cols="48"></textarea>
</body>
</html>

不知道你学了CSS没
刚学完HTML和CSS,这两个最好一起学
忽略这个答案,好像错了

“text-align: center”是文本水平居中,可以用div包裹textarea标签,设置div的class,如果需要垂直居中的话可以设置容器高度和行高值相同,也就是height 和 line-height值相同

你这个问题好像不太明确,究竟是一行居中,还是多行居中?
已解决,你看看是不是这样
满意请五星好评+返现0.00元
链接描述

textarea {
    display: flex;
    justify-content: center;
    align-items: center;
}

各大浏览器前缀自行添加

新手上路,请多包涵

我是48px的,我写了
padding-top: .75rem;
padding-bottom: .75rem;

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题