2013-09-27 179 views
0

我有一个asp.net表格,每行有1行和2个单元格。 我试图让右边的单元格显示在单元格的最右边缘附近,但没有成功。asp.net表格单元格水平排列

<asp:Table runat="server" ID="tblMyTable" BorderStyle="Solid" BorderWidth="1" BorderColor="Black" Font-Names="Arial" BackColor="White" Width="190" ClientIDMode="Static"> 
     <asp:TableRow Font-Names="Arial Black"> 
      <asp:TableCell HorizontalAlign="Left" CssClass="HeaderPadding"> 
       <asp:Label runat="server" ID="lblID" Text="361299"></asp:Label> 
      </asp:TableCell> 
      <asp:TableCell HorizontalAlign="Right"> 
       <asp:Label runat="server" ID="lblPercentage" Text="79%"></asp:Label> 
      </asp:TableCell> 
     </asp:TableRow> 
</Asp:Table> 

<style> 
.HeaderPadding 
    { 
     padding:0px 0px 10px 0px; 
    } 
</style> 

我要显示这样的:

enter image description here

我怎样才能正确对齐的百分比标签?

相反,它看起来像这样的一些细胞,但在别人看起来确定。

enter image description here

回答

2

试试这个:

<table> 
    <tr> 
     <td class="HeaderPadding"> 
      <asp:Label runat="server" ID="lblID" Text="361299"></asp:Label> 
     </td> 
     <td style="text-align: right"> 
      <asp:Label runat="server" ID="lblPercentage" Text="79%"></asp:Label> 
     </td> 
    </tr> 
</table> 
+0

下面

<style type="text/css"> .rightAlign { text-align:right; } </style> 

我已经找到了罪魁祸首。在较低的行中,我有包含各种长度文本的单元格。这似乎决定了顶级电池的使用时间。 –

+0

@sd_dracula如果您希望基于单元格中的数据长度不会增长/缩小的一致宽度,请考虑在'px'或'em'中使用CSS'width'设置。 –

0

你可以使用CSS类就像在你的标签

<asp:Label runat="server" ID="lblPercentage" Text="79%" CssClass="rightAlign"></asp:Label>