在 "textarea" 中居中文本,然后当用户在其中单击时从左侧输入

Centering text in "textarea" but then typing from left when the user clicks inside it

我在我的页面上使用带有占位符的文本区域元素。是否可以将文本区域内的占位符文本居中对齐,但当用户在框中单击时,他们会从左侧而不是中心开始书写?

提前致谢。

是的,使用class:focus仅在textarea元素获得焦点时应用css

像这样

textarea{
  text-align:center;
}

textarea:focus{
  text-align:left;
}

Fiddle 测试:

textarea{
  text-align:center;
}

textarea:focus{
  text-align:left;
}
<textarea rows="10" cols="60" placeholder="Input Your Text"></textarea>