简体   繁体   English

html / css如何在中间对齐(垂直)文本<textarea>

[英]html / css how to Middle (vertically) align text inside a <textarea>

I want to centre the text inside a text area; 我想将文本居中放置在文本区域内; I am trying with the line height, but it doesn't work. 我正在尝试调整行高,但是行不通。

屏幕截图

You could use the contenteditable="true" attribute on a <div> and then skin it with CSS. 您可以在<div>上使用contenteditable="true"属性,然后使用CSS对其进行外观设置。

Here is a link for cross browser compatibility: Reliable cross-browser info on ContentEditable 这是跨浏览器兼容性的链接: 有关ContentEditable的可靠跨浏览器信息

You can use padding only to achieve that, but it's not pretty way to do things. 您只能使用padding来达到目的,但这并不是完成任务的好方法。 You can also use jQuery to make the padding flexible, instead of just setting it by yourself. 您还可以使用jQuery使填充变得灵活,而不仅仅是您自己设置。

Hey now you can used input tag 嘿,现在您可以使用输入标签了

Replace textarea into input tag as like this 像这样将textarea替换为输入标签

and define height and line-height 并定义heightline-height

Css 的CSS

input[type="text"]{
line-height:125px;
    height:125px;
}

HTML 的HTML

<input type="text" value="">

Live demo http://jsfiddle.net/MTCrt/ 现场演示http://jsfiddle.net/MTCrt/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM