如何在html表格行中将文本居中对齐? [英] How to align center the text in html table row?
本文介绍了如何在html表格行中将文本居中对齐?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用HTML <table>
,并且我想将<td>
的文本与每个单元格的中心对齐.
I am using an HTML <table>
and I want to align the text of <td>
to the center in each cell.
如何使文本水平和垂直居中对齐?
How do I center align the text horizontally and vertically?
推荐答案
以下是带有CSS和内联style
属性的示例:
Here is an example with CSS and inline style
attributes:
td
{
height: 50px;
width: 50px;
}
#cssTable td
{
text-align: center;
vertical-align: middle;
}
<table border="1">
<tr>
<td style="text-align: center; vertical-align: middle;">Text</td>
<td style="text-align: center; vertical-align: middle;">Text</td>
</tr>
</table>
<table border="1" id="cssTable">
<tr>
<td>Text</td>
<td>Text</td>
</tr>
</table>
编辑:valign
属性在HTML5中已弃用,不应使用.
EDIT: The valign
attribute is deprecated in HTML5 and should not be used.
这篇关于如何在html表格行中将文本居中对齐?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文