How to align center the text in html table row?

后端 未结 7 2015
不思量自难忘°
不思量自难忘° 2020-12-07 17:05

I am using an HTML

and I want to align the text of
to the center in each cell.

How do I center align the text hori

相关标签:
7条回答
  • 2020-12-07 17:38

    The CSS to center text in your td elements is

    td {
      text-align: center;
      vertical-align: middle;
    }
    
    0 讨论(0)
  • 2020-12-07 17:39

    <td align="center"valign="center">textgoeshere</td>

    more on valign

    0 讨论(0)
  • 2020-12-07 17:40

    Selector > child:

    .text-center-row>th,
    .text-center-row>td {
      text-align: center;
    }
    <table border="1" width='500px'>
      <tr class="text-center-row">
        <th>Text</th>
        <th>Text</th>
        <th>Text</th>
        <th>Text</th>
      </tr>
      <tr>
        <td>Text</td>
        <td>Text</td>
        <td>Text</td>
        <td>Text</td>
      </tr>
      <tr class="text-center-row">
        <td>Text</td>
        <td>Text</td>
        <td>Text</td>
        <td>Text</td>
      </tr>
    </table>

    0 讨论(0)
  • 2020-12-07 17:45

    Try to put this in your CSS file.

    td {
        text-align: center;
        vertical-align: middle;
    }
    
    0 讨论(0)
  • 2020-12-07 17:50

    long hand inline example:

    <td style='text-align:center;vertical-align:middle'></td> 
    

    shorthand css example:

    td{
     text-align:center;
     vertical-align:middle;
    }
    
    0 讨论(0)
  • 2020-12-07 17:55

    <td align="center" valign="center">textgoeshere</td>

    Is the only correct answer imho, since your working with tables which is old functionality most common used for e-mail formatting. So your best bet is to not use just style but inline style and known table tags.

    0 讨论(0)
提交回复
热议问题