94

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

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?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
begiPass
  • 2,124
  • 6
  • 36
  • 57

9 Answers9

168

Try to use this 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;
}
Ícaro
  • 1,432
  • 3
  • 18
  • 36
wroniasty
  • 7,884
  • 2
  • 32
  • 24
24

Try this:

table { 
border-spacing: 0;
border-collapse: collapse;
}
zoom23
  • 694
  • 2
  • 10
  • 23
8

Use a display block

style= "display: block";
glennsl
  • 28,186
  • 12
  • 57
  • 75
yoko
  • 81
  • 1
  • 1
7

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

<table id="page" width="100%" border="0" cellspacing="0" cellpadding="0">
Kelderic
  • 6,502
  • 8
  • 46
  • 85
memer
  • 95
  • 1
  • 2
  • 4
    The accepted answer uses css padding and margin, which is the recommended alternative to cellspacing and cellpadding, which have been deprecated for many years now. And note that HTML5 does not support cellspacing and cellpadding. – ToolmakerSteve Apr 28 '16 at 05:00
6

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>
Vanda Ros
  • 107
  • 1
  • 5
3

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

Andrew
  • 18,680
  • 13
  • 103
  • 118
Nps
  • 1,638
  • 4
  • 20
  • 40
3

I find the most perfectly working answer is this

.noBorder {
    border: 0px;
    padding:0; 
    margin:0;
    border-collapse: collapse;
}
Kai Hayati
  • 59
  • 1
  • 2
0

I had exactly the same problem. That is a table with collapsed borders and <IMG images in each <TD cell. I had padding and margin set to zero on everything. Nothing would get rid of the bottom padding of the <IMG

Changing the CSS attribute of the <IMG tag to "display: block;" solved it. Thank-you - user yoko

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jul 09 '22 at 21:13
0

Remove Padding from Left and right side :

padding:0; margin:0;

for Table cell padding remove :

cellpadding : 0; cellspacing : 0;

  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jul 09 '22 at 21:20