Right align and left align text in same HTML table cell

前端 未结 8 1482
梦谈多话
梦谈多话 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:18

    Do you mean like this?

    <!-- ... --->
    <td>
       this text should be left justified
       and this text should be right justified?
    </td>
    <!-- ... --->
    

    If yes

    <!-- ... --->
    <td>
       <p style="text-align: left;">this text should be left justified</p>
       <p style="text-align: right;">and this text should be right justified?</p>
    </td>
    <!-- ... --->
    
    0 讨论(0)
  • 2020-12-08 04:18

    Tor Valamo's answer with a little contribution form my side: use the attribute "nowrap" in the "td" element, and you can remove the "width" specification. Hope it helps.

    <td nowrap>
      <div style="float:left;">this is left</div>
      <div style="float:right;">this is right</div>
    </td>
    
    0 讨论(0)
  • 2020-12-08 04:20

    If you want them on separate lines do what Balon said. If you want them on the same lines, do:

    <td>
      <div style="float:left;width:50%;">this is left</div>
      <div style="float:right;width:50%;">this is right</div>
    </td>
    
    0 讨论(0)
  • 2020-12-08 04:23

    You could use something like:

    <td> 
      <div style="float:left;width:49%;text-align:left;">this is left</div> 
      <div style="float:right;width:49%;text-align:right;">this is right</div> 
    </td>
    

    The 49% is to give some room for the renderer to wrap things around.

    And you can use either <div> or <span>

    0 讨论(0)
  • 2020-12-08 04:27

    I came up with this while trying to figure out how to display currency ('$' to left, number to right) in table cells:

    <div class="currency">20.34</div>
    
    .currency {
       text-align: right;
    }
    
    .currency:before {
       content: "$";
       float: left;
       padding-right: 4px;
    }
    
    0 讨论(0)
  • 2020-12-08 04:33

    sure but you need to wrap those "blocks" in separate tags and apply the alignment to those.

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