如何使用css使表格或文本居中 [英] How do I center a table or text using css

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

问题描述

如何使用css将表格或文本居中?

How do I center a table or text using css?

<table><tr><td class="ctr">
        <h1>Text</h1>
</td></tr></table>



css

.ctr {text-align:center;}?



旧方式:


css
.ctr{text-align:center;}?

The old way:

<center><table><tr><td class="ctr">
        <h1>Text</h1>
</td></tr></table></center>

推荐答案

如果你需要所有的桌子居中,那么

if you need all your tables centered then
table { text-align: center;}





任何特定的表格



Any particular table

#table-id { text-align: center}





仅限第一列



first column only

#table-id td:first-child {text-align: center }







请注意,使用表格进行布局(包含标题元素)是旧方法。你应该使用列,div(或者更好的是,




Note that using tables for the layout (to contain header elements) IS the old way. You should use columns, divs (or better yet,

<header>, <footer>, <aside>, <nav>, <section> and <article>

- HTML5元素)





如果您需要在页面中居中使用:

- HTML5 elements )


If you need to center the table in the page use:

table { margin: auto; }


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

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