User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the HTML and CSS section within the Web Development category of DaniWeb, a massive community of 397,845 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,429 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our HTML and CSS advertiser: Lunarpages Web Hosting
Views: 26493 | Replies: 10
Reply
Join Date: Mar 2004
Location: Brisbane
Posts: 632
Reputation: Slade has a spectacular aura about Slade has a spectacular aura about 
Rep Power: 7
Solved Threads: 6
Slade's Avatar
Slade Slade is offline Offline
Practically a Master Poster

CSS center vertical

  #1  
Jul 15th, 2004
Ok guys, here's the deal. I am using css for my website, everything is super duper, except for ONE page. It's the login page, I have used a table for the login box so as to position everything properly. What I want to know is, (btw the table is in a div) how do I vertically align my table to the center of the web page using css, is there a way at all? Otherwise I'm just going to have to use padding to get it away from the top a bit.
Formerly known as Slade.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Feb 2002
Location: Lawn Guylen, NY
Posts: 10,881
Reputation: cscgal is just really nice cscgal is just really nice cscgal is just really nice cscgal is just really nice cscgal is just really nice 
Rep Power: 32
Solved Threads: 108
Admin
Staff Writer
cscgal's Avatar
cscgal cscgal is offline Offline
The Queen of DaniWeb

Re: CSS center vertical

  #2  
Jul 15th, 2004
As far as I know, it's industry standard to set a padding or a margin. Can't seem to find a way to do it Check out http://www.stunicholls.myby.co.uk/ie/valign.html though.
Reply With Quote  
Join Date: Jun 2004
Posts: 38
Reputation: gooseneck is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 0
gooseneck's Avatar
gooseneck gooseneck is offline Offline
Light Poster

Re: CSS center vertical

  #3  
Jul 16th, 2004
My only problem with this technique has always been with the text being centered as well. I don't always want the text to be centered as well.

<-- Stumped
gooseneck Dave
Reply With Quote  
Join Date: Mar 2004
Location: Brisbane
Posts: 632
Reputation: Slade has a spectacular aura about Slade has a spectacular aura about 
Rep Power: 7
Solved Threads: 6
Slade's Avatar
Slade Slade is offline Offline
Practically a Master Poster

Re: CSS center vertical

  #4  
Jul 16th, 2004
I can acheive it on mozilla (firefox latest) and netscape (latest) but the other browsers hate it. Man why can't all browsers just have the same definition on things :mad:
Formerly known as Slade.
Reply With Quote  
Join Date: Jul 2004
Location: Wales
Posts: 735
Reputation: DaveSW is on a distinguished road 
Rep Power: 6
Solved Threads: 17
DaveSW's Avatar
DaveSW DaveSW is offline Offline
Master Poster

Re: CSS center vertical

  #5  
Jul 17th, 2004
It's simple to do actually. You use negative margins, and it works in IE5 upwards.

Here's a demo created by a mate of mine:
http://www.infinitypages.com/researc...entereddiv.htm
Reply With Quote  
Join Date: Feb 2002
Location: Lawn Guylen, NY
Posts: 10,881
Reputation: cscgal is just really nice cscgal is just really nice cscgal is just really nice cscgal is just really nice cscgal is just really nice 
Rep Power: 32
Solved Threads: 108
Admin
Staff Writer
cscgal's Avatar
cscgal cscgal is offline Offline
The Queen of DaniWeb

Re: CSS center vertical

  #6  
Jul 17th, 2004
While searching for a solution the other day, I came across using negative margins, but I was confused and didn't understand how they work. I'm still confused, actually. I checked out the CSS you provided - but I don't see how using negative margins centers the div?
Reply With Quote  
Join Date: Jun 2004
Posts: 38
Reputation: gooseneck is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 0
gooseneck's Avatar
gooseneck gooseneck is offline Offline
Light Poster

Re: CSS center vertical

  #7  
Jul 18th, 2004
That is wonderful! I had never thought of using margins, thanks for that great example!

Let me see if I can try to explain it without making too much of a fool out of myself. When you specify where the top and left are going to be, in this example both were 50%, that means that the top-left pixel of your box will be 50% from the top and 50% from the left. But that means your area isn't going to be centered. The top-left pixel will be. By moving the margins back towards the left and top(with the negative numbers, a positive would move it farther from the top and left) half the length and width of the area you are actually moving it to exactly where you want, right in the center!

I hope that makes sense. Take care!
gooseneck Dave
Reply With Quote  
Join Date: Mar 2004
Location: Brisbane
Posts: 632
Reputation: Slade has a spectacular aura about Slade has a spectacular aura about 
Rep Power: 7
Solved Threads: 6
Slade's Avatar
Slade Slade is offline Offline
Practically a Master Poster

Re: CSS center vertical

  #8  
Jul 18th, 2004
Originally Posted by gooseneck
half the length and width of the area

What area? The box you are trying to centre I assume?
Formerly known as Slade.
Reply With Quote  
Join Date: Jul 2004
Location: Wales
Posts: 735
Reputation: DaveSW is on a distinguished road 
Rep Power: 6
Solved Threads: 17
DaveSW's Avatar
DaveSW DaveSW is offline Offline
Master Poster

Re: CSS center vertical

  #9  
Jul 19th, 2004
Yes that's right.
Basically we are moving the control point of the box to the center by telling it to use margins that are negative and half the width and height of the box. This means that when we position it 50% from left and top we are moving the center of the box to that position.
If you want to see how it works insert the lines of code one at a time, and watch how it changes it. First apply your dimensions, then your negative margins. then put your positioning in. That's how I figured it out the first time Ryan showed me. I actually have a demo built into one of my very early attempts at web design: http://www.emdevelopments.co.uk/tollgate/first/

Hopefully that's a little clearer? Maybe? Maybe Not?

BTW, don't worry too much if negative margins has you baffled. I still don't get Ryan's latest http://www.alistapart.com/articles/negativemargins/
Reply With Quote  
Join Date: Feb 2002
Location: New York
Posts: 862
Reputation: Tekmaven is a glorious beacon of light Tekmaven is a glorious beacon of light Tekmaven is a glorious beacon of light Tekmaven is a glorious beacon of light Tekmaven is a glorious beacon of light 
Rep Power: 12
Solved Threads: 16
Moderator
Tekmaven's Avatar
Tekmaven Tekmaven is offline Offline
The C# Man, Myth, Legend

Re: CSS center vertical

  #10  
Jul 30th, 2004
Dave, thanks for this info. Just saved me! And great link to that alistapart site, just printed it out and saved it in my "Red Book of Knowledge" (where I put all the crap I want to remember..)
-Ryan Hoffman

ASP.NET Specialist / Webmaster, Extended64.com.
Please do not email or PM me with support questions. Please direct them to the forums instead.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb HTML and CSS Marketplace
Thread Tools Display Modes

Other Threads in the HTML and CSS Forum

All times are GMT -4. The time now is 7:55 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC