[SOLVED] Centering an image with CSS without moving anything else on the page.

This is a discussion on "[SOLVED] Centering an image with CSS without moving anything else on the page." within the Web Page Design section. This forum, and the thread "[SOLVED] Centering an image with CSS without moving anything else on the page. are both part of the Design Your Website category.



Go Back   Webforumz.com > Main Forums > Design Your Website > Web Page Design

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Oct 28th, 2007, 22:57
Ed Ed is online now
Highly Reputable Member
Join Date: Jul 2007
Location: Cork, Ireland
Posts: 692
Blog Entries: 1
Thanks: 0
Thanked 0 Times in 0 Posts
[SOLVED] Centering an image with CSS without moving anything else on the page.

Oh, I've looked and searched and all the methods move the menu, or skip a line.

How can I center an image so it's centered in all browsers, on all resolutions, and stay on the same line without affecting anything else?

http://www.simplifiedimpact.com/index.html

See above, the "SI" logo is centered on my laptop, but not on my desktop.
Every method I've tried (placing it within a centered <p> class, depreciated <center>..etc) moves the menu or skips a line, how can it stay on the line it's on and not budge anything else?

Surely it's simple?

Thanks,
Ed
Last Blog Entry: Happy New Year! (Dec 31st, 2007)
Reply With Quote

  #2 (permalink)  
Old Oct 28th, 2007, 23:17
SuperMember

SuperMember
Join Date: May 2007
Location: UK
Age: 27
Posts: 1,111
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Centering an image with CSS without moving anything else on the page.

It's really very simple.

Every item that you want to centre should have:
  • A specified width
  • margin: 0 auto
(This will also set top/bottom margins to nothing. You can of course change that.)

Now everything should be centred in all browsers except IE 5. It's unnecessary to bother with IE 5 (hardly anyone uses it), but if you wish to fix it I can show you the hack.

So, why is this failing to work for your logo, yet succeeding for the other two items? Well, <img>s are inline elements. You need to make it display as a block-level element. Inline elements are not formatted in the same way.

You can do this with the CSS display: block applied to your <img>. Now it will act as a block box, so the margins will work.
Reply With Quote
  #3 (permalink)  
Old Oct 28th, 2007, 23:21
Ed Ed is online now
Highly Reputable Member
Join Date: Jul 2007
Location: Cork, Ireland
Posts: 692
Blog Entries: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Centering an image with CSS without moving anything else on the page.

Now with me...(yeah I know annoying)

The easier you make it sound, the more confused.

If I was to put this directly into css and html what exactly would it look like?


Thanks so much,
Ed
Last Blog Entry: Happy New Year! (Dec 31st, 2007)

Last edited by Ed; Oct 28th, 2007 at 23:33. Reason: FORGOT to include CSS, making me look stupid.
Reply With Quote
  #4 (permalink)  
Old Oct 29th, 2007, 00:00
SuperMember

SuperMember
Join Date: May 2007
Location: UK
Age: 27
Posts: 1,111
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Centering an image with CSS without moving anything else on the page.

HTML:

Code: Select all
<img id="logo" src="http://simplifiedimpact.com/images57/silogo.png">
CSS:

Code: Select all
#logo {
display: block;
margin: 0 auto;
}
Reply With Quote
  #5 (permalink)  
Old Oct 29th, 2007, 11:28
Ed Ed is online now
Highly Reputable Member
Join Date: Jul 2007
Location: Cork, Ireland
Posts: 692
Blog Entries: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Centering an image with CSS without moving anything else on the page.

Works Perfectly...thank You!

Ed
Last Blog Entry: Happy New Year! (Dec 31st, 2007)
Reply With Quote
  #6 (permalink)  
Old Oct 29th, 2007, 11:34
SuperMember

SuperMember
Join Date: May 2007
Location: UK
Age: 27
Posts: 1,111
Thanks: 0
Thanked 0 Times in 0 Posts
Re: [SOLVED] Centering an image with CSS without moving anything else on the page.

A pleasure.
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Moving image show further up the page to look OK in IE and firefox. alicanteman Web Page Design 2 Jan 19th, 2008 11:37
[SOLVED] page centering issues VanderBOOM Web Page Design 12 Dec 4th, 2007 15:06
[SOLVED] image to centre page R8515198 Web Page Design 6 Nov 23rd, 2007 04:11
[SOLVED] Centering a layer based page for different screen sizes? Mulith Starting Out 11 Oct 31st, 2007 02:40
Centering an image on my web page Fysicus Web Page Design 8 Sep 21st, 2007 12:43


All times are GMT. The time now is 16:14.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43