Click to See Complete Forum and Search --> : <h> and Margin


ozpo1
02-13-2007, 02:52 PM
Hi, I'm trying to set the margin of my haeders<h1><h2>..., but I found out that it's being avoid. Is there a problem using the margin option in css with headers?
And if so, how can I set the headers margin?
Thanks, Oz.

toicontien
02-13-2007, 03:05 PM
h1 {
margin: 1em 0;
}
... should be all you need for H1, as an example. The code above is a short cut to setting the top and bottom margins, and the left and right margins. You might like W3Schools CSS tutorials: www.w3schools.com/css/

ozpo1
02-13-2007, 03:17 PM
Thanks for the fast reply.
My problem is that the code doesn't work for me when I do margin-top:5em.
For left and right it works. Any idea why, or how can I fix it?
Thanks again, Oz.

WebJoel
02-13-2007, 04:09 PM
...My problem is that the code doesn't work for me when I do margin-top:5em.
For left and right it works. Any idea why, or how can I fix it?... That should work. For clarity though, -are you putting this in your <style><style>, or inline to the <h> tag? That is to say:
(in your CSS) :

<style>
h1 {margin-top:5em;}
</style>

or in your HTML "

<h1 style="margin-top:5em;">Top-level header</h1>

Either of these would work.

Centauri
02-13-2007, 04:10 PM
Depends on what is above the <h> tag. If there isn't a valid "solid" object above the <h> element (like an empty div with no border for example), the margin will collapse. In these circumstances, a padding-top may work better.

Cheers
Graeme