html 怎么让文本框中的文字居中

如题所述

可以用增高行距的办法变通实现垂直居中,完整代码如下:

<html>
<head>
<style>
body{TEXT-ALIGN: center;}
#center{ MARGIN-RIGHT: auto;
MARGIN-LEFT: auto;
height:200px;
background:#F00;
width:400px;
vertical-align:middle;
line-height:200px;
}
</style>
</head>
<body >
<div id="center"><p>test content</p></div>
</body>
</html>
温馨提示:答案为网友推荐,仅供参考
第1个回答  2016-07-27
<input id="myinput" style="width:150; text-align:center" value="122"/>
第2个回答  2016-07-27
1
2
3
4
5
6
7

<!--不管是使用表格 还是DIV 或者是其他标签 出了文本或者包涵的标签 其他任何标签是不可使直接使用文本居中的样式 标签是可以 使用 margin:auto 样式-->
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="center"><input name="" type="text" /></td>
</tr>
</table>
<div style="<a href="https://www.baidu.com/s?wd=text-align&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1dBmhwWuhD1uhcvnjPBnHmv0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EnHTYrHDLnjnvnHf4PW0zrHcY" target="_blank" class="baidu-highlight">text-align</a>:center;"><input name="" type="text" /></div>