77

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,195
  • 62
  • 50
  • 120
begiPass
  • 1,904
  • 6
  • 33
  • 56

7 Answers7

138

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
  • 864
  • 13
  • 28
wroniasty
  • 7,102
  • 2
  • 28
  • 24
20

Try this:

table { 
border-spacing: 0;
border-collapse: collapse;
}
zoom23
  • 614
  • 2
  • 10
  • 22
5

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">
Andy Mercer
  • 5,605
  • 5
  • 40
  • 80
memer
  • 67
  • 1
  • 2
  • 3
    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
5

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
  • 77
  • 1
  • 5
5

Use a display block

style= "display: block";
glennsl
  • 23,127
  • 11
  • 49
  • 65
yoko
  • 51
  • 1
  • 1
3

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

Andrew
  • 13,934
  • 8
  • 78
  • 93
Nps
  • 1,568
  • 4
  • 18
  • 37
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