开发者

align text to the right in table

I have the following html

<div style="width:700px">
<table>
     <tr&开发者_开发技巧gt;
          <td align="right">
               some text here
          </td>
     </tr>
</table>
</div>

I would like the text to be aligned to the right, however it remains aligned to the left. Why?

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


You have to define the width: 700px; inside your table tag. The problem now is that your table isn't just wide enough: http://jsfiddle.net/qMAT3/


Try putting borders on your elements. It will demonstrate why.

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

By default, tables size to their contents, not their wrappers. You need to add width="100%" to your table markup.


Try this:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜