如何将 HTML 表格的内容居中? [英] How to center the contents of an HTML table?

查看:41
本文介绍了如何将 HTML 表格的内容居中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 HTML

并且我想将
的文本与每个单元格的中心对齐.

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/

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

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

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

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