Forum Moderators: not2easy

Message Too Old, No Replies

Centering Header in Div?

         

pab1953

3:49 pm on Dec 17, 2008 (gmt 0)

10+ Year Member



I have a header as a background image in a div. I want to center it but it won't. Any ideas?

Thanks.

rocknbil

4:04 pm on Dec 17, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try

#header { width: 900px; margin: auto; }

for whatever your header width is, or

#header { text-align:center; }

Even if it's an image and not "text".

It's always helpful in any problems with positioning to put a border on the element temporarily to see what's happening:

#header { width: 900px; margin: auto; border: 1px solid #ff0000; }
#header img { border: 1px solid #00ff00; }

You'll see by default the div will be the full width of any element containing it.

pab1953

4:09 pm on Dec 17, 2008 (gmt 0)

10+ Year Member



Rocknbil, margin:auto did the trick. Why?

(BTW Thanks!)

samir0602

12:56 pm on Jan 14, 2009 (gmt 0)

10+ Year Member



sure this will help you

#header
{
width: "your page width";
margin: auto 0;
}