简体   繁体   English

HTML将文本中心对齐在同一行

[英]HTML Align text center at the same line

I was trying to align my text in my table and I'm wondering how do this. 我试图在table对齐我的文字,我想知道这是怎么做的。

My code: 我的代码:

 <table class="n"> <tbody> <tr> <td style="text-align:center"><strong>TITLE</strong></td> <td style="text-align:center"><strong>TITLE</strong></td> </tr> <tr> <td style="text-align:center">A</td> <td style="text-align:center"><strong>MESSAGE TEST</strong></td> </tr> <tr class="alt"> <td style="text-align:center">C</td> <td style="text-align:center"><strong>message test lasdadlong</strong></td> </tr 

Fiddle 小提琴

is there anyway of edit the text so everything start at the same line ? 无论如何编辑文本所以一切都从同一行开始?

Desired output: 期望的输出:

在此输入图像描述

Solution: 解:

  • remove text-align:center from last td in each tr 从每个tr最后一个td删除text-align:center

Notes: 笔记:

Avoid inline CSS, use external CSS 避免使用内联CSS,使用外部CSS

 tr td:first-of-type { text-align: center } 
 <table class="n"> <tbody> <tr> <td><strong>TITLE</strong> </td> <td><strong>TITLE</strong> </td> </tr> <tr> <td>A</td> <td><strong>MESSAGE TEST</strong> </td> </tr> <tr class="alt"> <td>C</td> <td><strong>message test lasdadlong</strong> </td> </tr> </tbody> </table> 

 <center><table class="n"> <tbody> <tr> <td style="text-align:center"><strong>TITLE</strong></td> </tr> <tr> <td style="text-align:center"><strong>MESSAGE TEST</strong></td> </tr> <tr class="alt"> <td style="text-align:center"><strong>message test lasdadlong</strong></td> </tr></center> 

I have edited your code as your mentioned image, Post again edited to stable table on center. 我已将您的代码编辑为您提到的图像,Post再次编辑到中心的稳定表格。 Hope it works for you. 希望对你有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM