85

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,438
  • 68
  • 55
  • 126
begiPass
  • 2,004
  • 6
  • 34
  • 57

7 Answers7

153

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,082
  • 1
  • 18
  • 34
wroniasty
  • 7,474
  • 2
  • 30
  • 24
21

Try this:

table { 
border-spacing: 0;
border-collapse: collapse;
}
zoom23
  • 634
  • 2
  • 10
  • 22
7

Use a display block

style= "display: block";
glennsl
  • 25,730
  • 12
  • 57
  • 71
yoko
  • 71
  • 1
  • 1
6

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
  • 6,124
  • 7
  • 44
  • 82
memer
  • 85
  • 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
  • 97
  • 1
  • 5
3

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

Andrew
  • 16,273
  • 10
  • 93
  • 104
Nps
  • 1,618
  • 4
  • 19
  • 38
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