如何在html表格行中将文本居中对齐? [英] How to align center the text in html table row?

查看:1373
本文介绍了如何在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>

http://jsfiddle.net/j2h3xo9k/

编辑:valign属性在HTML5中已弃用,不应使用.

EDIT: The valign attribute is deprecated in HTML5 and should not be used.

这篇关于如何在html表格行中将文本居中对齐?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆