0

I'm trying to remove the 8px margin from the body tag.

I've tried (not all at once)

 * { padding:0; margin:0; }

and

 html, body { padding:0; margin:0 !important; }

and

 body { margin:-8px; }

and even

 <body style="margin:0">

The last one works, but only if I add the style attrib using Firebug; if it's in the original HTML, it gets ignored.

I'm at my wit's end.

Edit: facepalm I figured it out; I'd changed it to a cfm so I could easily call browser-specific styles. Thank you all for your help.

zzxjoanw
  • 374
  • 4
  • 16
  • When checking in FireBug, can you see any other styles being applied? It may be overridden – Curtis Mar 29 '12 at 15:24
  • The only margin listed on the body tag comes from FF's stylesheet; the one I added doesn't show. – zzxjoanw Mar 29 '12 at 15:31
  • @zzjoanw - That's interesting. Your stylesheet probably isnt linked right. Include your HTML for linking your stylesheet in your question – Curtis Mar 29 '12 at 15:33

4 Answers4

2

Include a reset stylesheet instead, this way you will reset all of the default values equally in all browsers.

http://meyerweb.com/eric/tools/css/reset/

Andres I Perez
  • 75,075
  • 21
  • 157
  • 138
  • 1
    Since I'm (currently) only interested in the body margin, how is that going to work better than what I've done? – zzxjoanw Mar 29 '12 at 15:29
  • 1
    You have already exhausted all tries of removing the margin from the body tag, including using the `!important` rule and still nothing, maybe its another tag which is causing the margin and not the body tag? With a reset sheet you will target all of the elements in one go and so it might work. Otherwise you will need to post a test site so we can take a look, because all you're going to get are guesses. – Andres I Perez Mar 29 '12 at 15:33
0

All you need is:

body { margin: 0; padding: 0; }

The padding is not needed for Firefox, but for Opera, which uses padding instead of margin for the default.

Demo: http://jsfiddle.net/k3j8Y/

Guffa
  • 687,336
  • 108
  • 737
  • 1,005
0
body{ margin: 0;}

works ok for me :P

Enrique Moreno Tent
  • 24,127
  • 34
  • 104
  • 189
0

Include your stylesheet correctly

As your style is not appearing in FireBug's CSS rule stack, your CSS is probably not linked correctly. Ensure the stylesheet is in your head tag like so:

<head>
    <link href="Style.css" rel="stylesheet" type="text/css" />
</head>
Curtis
  • 101,612
  • 66
  • 270
  • 352