Html 如何在表格右侧添加边距

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9403050/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 22:43:46  来源:igfitidea点击:

How to add margin right to table

htmlcss

提问by NoviceMe

I have following html:

我有以下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>

I want to add 100px margin from right of the screen. i tried adding margin-right and removing width =100% it is not working.

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

回答by Sebastian Siek

margin-right will not work if you set width to 100%. What you could do is :

如果您将宽度设置为 100%,则 margin-right 将不起作用。你可以做的是:

  1. wrap table in a div tag. add margin to div
  2. set table width to 100%
  1. 将表格包装在 div 标签中。为 div 添加边距
  2. 将表格宽度设置为 100%

UPDATEDIf you are creating a page layout, then you should be using divs instead of tables. Tables are appropriate for data display (like custom grid style view).

更新如果您正在创建页面布局,那么您应该使用 div 而不是表格。表格适用于数据显示(如自定义网格样式视图)。

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

Hope it helps.

希望能帮助到你。

回答by jcubic

You need to add td tags and you forget to close width atribute:

您需要添加 td 标签并且忘记关闭宽度属性:

<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>

回答by Ajay

Just use this

就用这个

<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>