2011-04-13 178 views
0

我有以下的HTML對齊文本右表

<div style="width:700px"> 
<table> 
    <tr> 
      <td align="right"> 
       some text here 
      </td> 
    </tr> 
</table> 
</div> 

我想文本對齊到正確的,但它仍然左對齊。爲什麼?

的jsfiddle:http://jsfiddle.net/kralco626/WBejT/1/

+0

呵呵?你什麼意思? – 2011-04-13 13:25:42

+0

@丹尼爾 - 錯字,我的壞(現在修復) – kralco626 2011-04-13 13:27:20

回答

2

你必須定義寬度:700像素;在你的餐桌標籤內。現在的問題是您的桌子不夠寬: http://jsfiddle.net/qMAT3/

+0

完美,我剛剛添加'樣式=「寬度:100%」''我的表格標籤 – kralco626 2011-04-13 13:30:23

0

試試這個:

<div style="width:700px"> 
    <table width="100%"> 
    <tr> 
     <td width="20%" style="text-align:right"> some text here </td> 
    </tr> 
    </table> 
</div> 
2

嘗試在您的元素上放置邊框。它會證明爲什麼。

<div style="width:700px;border:1px solid #000000"> 
<table border="1"> 
    <tr> 
      <td align="right"> 
       some text here 
      </td> 
    </tr> 
</table> 
</div> 

默認情況下,表大小爲其內容,而不是其包裝。您需要將width="100%"添加到您的表格標記。

+0

是的,這就是我最終做的 – kralco626 2011-04-13 13:31:41