如何向表添加边距权限

时间:2012-02-22 21:10:00

标签: html css

我有以下html:

<table width="100%;>
        <tr><hr style="width:100%;"></hr></tr>
        <tr>
            <span style="float:left">abc</span>
            <span class="noindex" style="float:right">PageID</span>
        </tr>
        <br/>
        <tr>Some text here...</tr>
</table>

我想从屏幕右侧添加100px的边距。我尝试添加margin-right并删除width = 100%它不起作用。

3 个答案:

答案 0 :(得分:14)

如果将宽度设置为100%,

margin-right将不起作用。 你能做的是:

  1. 将表格包装在div标签中。为div添加保证金
  2. 将表格宽度设置为100%
  3. <强>已更新 如果要创建页面布局,则应使用div而不是表。表适用于数据显示(如自定义网格样式视图)。

    <div>
        <div style="margin-right:100px">
            <table style="width:100%">
                //your table
            </table>
        </div>
    </div>
    

    希望它有所帮助。

答案 1 :(得分:3)

您需要添加td标记,而忘记关闭width属性:

<table width="100%" style="margin-right:100px">
    <tr><td><hr style="width:100%;"></hr></td></tr>
    <tr><td>
        <span style="float:left">abc</span>
        <span class="noindex" style="float:right">PageID</span></td>
    </tr>
    <tr><td>Some text here...</td></tr>
</table>

答案 2 :(得分:-5)

请使用此

<table width="100%" style="margin-right:100px;">
    <tr><hr style="width:100%;"></hr></tr>
    <tr>
        <span style="float:left">abc</span>
        <span class="noindex" style="float:right">PageID</span>
    </tr>
    <br/>
    <tr>Some text here...</tr>
  </table>
相关问题