Forum Moderators: not2easy

Message Too Old, No Replies

Horizontally centering an image

         

Jeremy_H

12:10 am on Apr 1, 2006 (gmt 0)

10+ Year Member



Hello,

There has to be a simple solution to this, but I'm having a hard time figuring this out. I'm trying to horizontally center an image on the page.

Here's what my HTML looks like:

<p id="c"><img src="/1.jpg"></p>

And the CSS that isn't working:

#c{width:596px}
#c img{width:238px;height:288px;margin:auto}

Any help would greatly be appreciated.

twist

1:06 am on Apr 1, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



#c img{width:238px;height:288px;margin:0 auto; display:block}

Does that work?

Jeremy_H

1:50 am on Apr 1, 2006 (gmt 0)

10+ Year Member



Thank you, that worked great.

I've also come across a similar horizontal center problem. I'm trying to center some list items.

HTML:

<ul id="n"><li><a href="/">1</a></li><li><a href="/">2</a></li></ul>

CSS:

#n{display:block;margin:auto}

The similar trick didn't work. Anybody have any ideas?

Thanks

Old_Honky

7:41 pm on Apr 1, 2006 (gmt 0)

10+ Year Member Top Contributors Of The Month



Have you tried putting the list inside a div and centering the div?