删除所有填充和边距表 HTML 和 CSS

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16427903/
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-29 22:48:08  来源:igfitidea点击:

Remove all padding and margin table HTML and CSS

csshtml-tablemarginpadding

提问by begiPass

I have this table :

我有这张桌子:

<body>
    <table id="page" >
        <tr id="header" >
            <td colspan="2" id="tdheader" >je suis</td>
        </tr>
        <tr>
            <td>1</td>
            <td>2</td>
        </tr>
    </table>
</body>

and here is the css

这是css

html, body, #page {
    height:100%;
    width:100%;
    margin:0;
    padding:0;
}

#header {
    margin:0;
    padding:0;
    height:20px;
    background-color:green;
}

and I want to remove all margin and padding but always I have that :

我想删除所有边距和填充,但我总是有:

enter image description here

在此处输入图片说明

How can I resolve this?

我该如何解决这个问题?

回答by wroniasty

Try to use this CSS:

尝试使用这个 CSS:

/* Apply this to your `table` element. */
#page {
   border-collapse: collapse;
}

/* And this to your table's `td` elements. */
#page td {
   padding: 0; 
   margin: 0;
}

回答by zoom23

Try this:

尝试这个:

table { 
border-spacing: 0;
border-collapse: collapse;
}

回答by memer

Tables are odd elements. Unlike divs they have special rules. Add cellspacingand cellpaddingattributes, set to 0, and it should fix the problem.

表格是奇数元素。与divs不同,它们有特殊的规则。添加cellspacingcellpadding属性,设置为0,它应该可以解决问题。

<table id="page" width="100%" border="0" cellspacing="0" cellpadding="0">

回答by Vanda Ros

Try using tag body to remove all margin and padding like that you want.

尝试使用标签正文删除您想要的所有边距和填充。

<body style="margin: 0;padding: 0">
    <table border="1" width="100%" cellpadding="0" cellspacing="0" bgcolor=green>
        <tr>
            <td >&nbsp;</td>
            <td>&nbsp;</td>
        </tr>
        <tr>
            <td >&nbsp;</td>
            <td>&nbsp;</td>
        </tr>
        <tr>
            <td >&nbsp;</td>
            <td>&nbsp;</td>
        </tr>
    </table>
</body>

回答by yoko

Use a display block

使用显示块

style= "display: block";

回答by Nps

Remove padding between cells inside the table. Just use cellpadding=0and cellspacing=0attributes in table tag.

删除表格内单元格之间的填充。只需在表标签中使用cellpadding=0cellspacing=0属性。

回答by Kai Hayati

I find the most perfectly working answer is this

我发现最完美的工作答案是这个

.noBorder {
    border: 0px;
    padding:0; 
    margin:0;
    border-collapse: collapse;
}