Html 如何保持文本与文本区域的中间对齐? 这应该和盒子的中间平齐! 文本在这里!

Html 如何保持文本与文本区域的中间对齐? 这应该和盒子的中间平齐! 文本在这里!,html,css,Html,Css,如何使方框左侧的文本与方框中间保持水平,即使它被拖来拖去?这可以用CSS完成,还是需要Javascript?最简单的方法(如果您想避免使用表格)是浮动标签,并将其行高设置为等于textarea高度: 请参见这确实有效 <html> <body> This should be level with the middle of the box! <textarea id="id" name="name" rows="9" cols="50">Text is in

如何使方框左侧的文本与方框中间保持水平,即使它被拖来拖去?这可以用CSS完成,还是需要Javascript?

最简单的方法(如果您想避免使用表格)是浮动标签,并将其行高设置为等于textarea高度:

请参见

这确实有效

<html>
<body>

This should be level with the middle of the box!
<textarea id="id" name="name" rows="9" cols="50">Text is in here!</textarea>

</body>
</html>

这应该和盒子的中间平齐!
文本在这里!

您可以将
垂直对齐
属性与
显示:表格单元格一起使用。下面是一个示例,HTML:

<table>
<tr>
   <td valign="center">This should be level with the middle of the box!</td>
   <td>
         <textarea cols="40" rows="20">Text is in here!</textarea>
   </td>
</tr>
</table>
还有一个小演示:


我希望这有帮助

您需要将文本和文本区域都设置为
垂直对齐:中间
。HTML示例:

.middletext{
垂直对齐:中间对齐;
}
#身份证{
垂直对齐:中间对齐;
}

这应该和盒子的中间平齐!
文本在这里!

您应该显示相关的CSS。您发布的代码最终不会看起来像您链接的屏幕截图。中间,如垂直中间,而不是中间。在阅读了更多内容后,我决定放弃表格,转而使用垂直对齐方法。这正是我想要的,非常感谢!你也是,@codingbiz,还有其他给出解决方案的人!表格只能用于表格数据。如果你正在制作一个标准的表格,那么表格确实适合这个模子。
<div class = "wrapper">
    <div class = "text">
        I'm in the middle! Glee is awesome!
    </div>
    <textarea id="id" name="name" rows="9" cols="20">Text is in here!</textarea>
</div>
.wrapper {
    vertical-align: middle;
    display: table-row;    
}
.wrapper textarea {
    display: table-cell;
}
.text {
    display: table-cell;
    height: 100%;
    vertical-align: middle;
}