Right align and left align text in same HTML table cell

前端 未结 8 1483
梦谈多话
梦谈多话 2020-12-08 03:52

I have a cell in an HTML

. I would like part of the cell contents to be left justified and part to be right justified. Is this possible?

相关标签:
8条回答
  • 2020-12-08 04:42

    td style is not necessary but will make it easier to see this example in browser

    <table>
     <tr>
      <td style="border: 1px solid black; width: 200px;">
      <div style="width: 50%; float: left; text-align: left;">left</div>
      <div style="width: 50%; float: left; text-align: right;">right</div>
      </td>
     </tr>
    </table>
    
    0 讨论(0)
  • 2020-12-08 04:45

    It is possible but how depends on what you are trying to accomplish. If it's this:

    | Left-aligned       Right-aligned | in one cell then you can use floating divs inside the td tag:

    <td>
    <div style='float: left; text-align: left'>Left-aligned</div>
    <div style='float: right; text-align: right'>Right-aligned</div>
    </td>
    

    If it's | Left-aligned
                                               Right Aligned |

    Then Balon's solution is correct.

    If it's: | Left-aligned    |   Right-Aligned |

    Then it's:

    <td align="left">Left-aligned</td>
    <td align="right">Right-Aligned</td>
    
    0 讨论(0)
提交回复
热议问题