Position image in the dead center of my webpage

This is a discussion on "Position image in the dead center of my webpage" within the Web Page Design section. This forum, and the thread "Position image in the dead center of my webpage 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 Sep 21st, 2007, 09:22
New Member
Join Date: Sep 2007
Location: Antwerp, Belgium
Age: 33
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Position image in the dead center of my webpage

I need to get my image centered in the middle of my webpage, so when a browser using a resolution greater then 800x600 is used the imaged is cleanly centered in the middle of the screen.

I've been playing around with my CSS-settings, but so far no luck.

.oneColElsCtr #container {
width: 46em;
background: #FFFFFF;
margin: 0 auto; /* the auto margins (in conjunction with a width) center the page */
text-align: left; /* this overrides the text-align: center on the body element. */
}


Can anyone tell me what I need to add to get my image to center properly?
Reply With Quote

  #2 (permalink)  
Old Sep 21st, 2007, 09:48
Up'n'Coming Member
Join Date: Sep 2007
Location: Wales, UK
Age: 35
Posts: 88
Thanks: 1
Thanked 0 Times in 0 Posts
Send a message via MSN to robbied72 Send a message via Skype™ to robbied72
Re: Position image in the dead center of my webpage

Quote:
Originally Posted by Fysicus View Post
I need to get my image centered in the middle of my webpage, so when a browser using a resolution greater then 800x600 is used the imaged is cleanly centered in the middle of the screen.

I've been playing around with my CSS-settings, but so far no luck.

.oneColElsCtr #container {
width: 46em;
background: #FFFFFF;
margin: 0 auto; /* the auto margins (in conjunction with a width) center the page */
text-align: left; /* this overrides the text-align: center on the body element. */
}


Can anyone tell me what I need to add to get my image to center properly?
have you tried margin-left:auto; and margin-right:auto;
Reply With Quote
  #3 (permalink)  
Old Sep 21st, 2007, 09:48
AdRock's Avatar
SuperMember

SuperMember
Join Date: Jul 2006
Location: Devon, England
Posts: 565
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to AdRock
Re: Position image in the dead center of my webpage

Why don't you try to position the image like using top and left

Scrap that!!!

Why doin't you create a div to hold the image and align that center instead

Last edited by AdRock; Sep 21st, 2007 at 09:52.
Reply With Quote
  #4 (permalink)  
Old Sep 21st, 2007, 10:24
Up'n'Coming Member
Join Date: Sep 2007
Location: Wiltshire, UK
Age: 19
Posts: 82
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Position image in the dead center of my webpage

i read an interesting article somewhere. if you use the following code it works perfectly:

eg.
a 200x100 image

for horizontal center
{position:absolute; left:50%; margin-left:-100px;}

for vertical center
{position:absolute; top:50%; margin-top:-50px;}

basically the margin is half of the width of the element in negative

hope this helps
Reply With Quote
  #5 (permalink)  
Old Sep 21st, 2007, 10:25
Up'n'Coming Member
Join Date: Sep 2007
Location: Wiltshire, UK
Age: 19
Posts: 82
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Position image in the dead center of my webpage

oh yeah, so for both you use both in the same bit...

{position:absolute; left:50%; top:50%; margin-left:-100px; margin-top:-50px;}
Reply With Quote
  #6 (permalink)  
Old Sep 21st, 2007, 14:38
New Member
Join Date: Sep 2007
Location: Antwerp, Belgium
Age: 33
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Position image in the dead center of my webpage

Perfect. It works. Thanks very much dude

I changed my css to:

.oneColElsCtr #container {
position: absolute;
width: 46em;
left: 50%;
top: 50%;
background: #FFFFFF;
/* margin: 0 auto; the auto margins (in conjunction with a width) center the page */
margin-left: -400px;
margin-top: -300px;
text-align: left; /* this overrides the text-align: center on the body element. */
}


And the image alligns perfectly.
Reply With Quote
  #7 (permalink)  
Old Sep 26th, 2007, 06:55
alexgeek's Avatar
Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,769
Blog Entries: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alexgeek
Re: Position image in the dead center of my webpage

That's helpful, a lot of people need absolute centered pages for splash pages.
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
  #8 (permalink)  
Old Sep 26th, 2007, 08:38
Up'n'Coming Member
Join Date: Sep 2007
Location: Wiltshire, UK
Age: 19
Posts: 82
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Position image in the dead center of my webpage

please note: i havent tested this in IE6. when i have used similar principles on other pages i have found that IE6 hasnt displayed it properly. so watch out. someone might want to check this!!
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
how to center webpage daan Web Page Design 20 Jan 4th, 2008 00:25
How to center an image Pádraig Starting Out 8 Jun 12th, 2007 12:27
how to center my webpage? wasku Web Page Design 10 Jan 4th, 2007 20:14
center align text/background image Lchad Web Page Design 5 Dec 5th, 2006 10:40
Center image within div hessodreamy Web Page Design 6 Nov 28th, 2005 11:58


All times are GMT. The time now is 03:36.


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