Welcome to Dream.In.Code
Become an Expert!

Join 150,020 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,501 people online right now. Registration is fast and FREE... Join Now!




css -- using absolute positioning AND aligning in center of page

 
Reply to this topicStart new topic

css -- using absolute positioning AND aligning in center of page, i'm confused.

bazookatooth
12 Dec, 2006 - 09:31 AM
Post #1

D.I.C Head
**

Joined: 25 Oct, 2006
Posts: 56


My Contributions


Ok... take a look -> HERE


I have created the entire layout using absolute positioning. I am now happy with the design... however, I would like for it to load in the center of a viewer's browser window. Seeing that I've already used absolute positioning to layout EVERYTHING on the page, I don't know how to go about this..

Someone help please?
User is offlineProfile CardPM
+Quote Post

bazookatooth
RE: Css -- Using Absolute Positioning AND Aligning In Center Of Page
12 Dec, 2006 - 05:41 PM
Post #2

D.I.C Head
**

Joined: 25 Oct, 2006
Posts: 56


My Contributions
what, no "RTFM!" or anything?
User is offlineProfile CardPM
+Quote Post

bazookatooth
RE: Css -- Using Absolute Positioning AND Aligning In Center Of Page
13 Dec, 2006 - 07:32 PM
Post #3

D.I.C Head
**

Joined: 25 Oct, 2006
Posts: 56


My Contributions
this can't possibly be THAT hard.
User is offlineProfile CardPM
+Quote Post

capty99
RE: Css -- Using Absolute Positioning AND Aligning In Center Of Page
13 Dec, 2006 - 07:35 PM
Post #4

the real kya
Group Icon

Joined: 26 Apr, 2001
Posts: 9,256



Thanked: 16 times
Dream Kudos: 550
My Contributions
someone will answer if they know it.
stop boosting your thread.

User is online!Profile CardPM
+Quote Post

bazookatooth
RE: Css -- Using Absolute Positioning AND Aligning In Center Of Page
13 Dec, 2006 - 10:26 PM
Post #5

D.I.C Head
**

Joined: 25 Oct, 2006
Posts: 56


My Contributions
QUOTE(capty99 @ 13 Dec, 2006 - 08:35 PM) *

someone will answer if they know it.
stop boosting your thread.



ok.. i'll just let you do it for me, genius. thanks.
User is offlineProfile CardPM
+Quote Post

Arbitrator
RE: Css -- Using Absolute Positioning AND Aligning In Center Of Page
16 Dec, 2006 - 04:53 AM
Post #6

D.I.C Regular
Group Icon

Joined: 26 Jan, 2005
Posts: 492



Thanked: 2 times
My Contributions
You can absolutely position elements relative to a container element instead of the viewport by surrounding all of the absolutely positioned content with a relatively positioned element. Example:

div#container { position: relative; margin: 0 auto; }

With that, you can set dimensions on and center the container element and all of your absolutely positioned content inside of it will be absolutely positioned relative to the div#container element (instead of the viewport).

Note that you DO need to set the dimensions since they will effectively be zero by zero because absolutely positioned content is removed from the normal document flow and the container element will thus not take into account all of the elements it “contains” to define its dimensions dynamically. This means that you need to explicitly specify exactly how wide and tall your container element should be for it to be drawn at all. If you have trouble seeing its boundaries, assign it a noticeable background color.

Note also that in order for this technique to work, you’re probably going to need to fix some errors in your code since it’s invalid. Most critically, you need a document type declaration; you seem to be using XHTML, but the declaration indicating that the document is in fact XHTML is missing. As a result, your document is being rendered in backward‐compatibility (or quirks) mode. In quirks mode, the browser intentionally renders the page incorrectly in an attempt to display poorly coded legacy documents as originally intended.

I briefly experimented with your code using Firefox’s Web Developer Extension and couldn’t get the technique I described to work, so I assume that your invalid code will need to be fixed first. Make sure that you validate the document after you’ve added a doctype declaration so that you can see all of the errors that need fixing. Additionally, if you still don’t comprehend how the technique works, try looking up “making the absolute relative” in a Web search.

This post has been edited by Arbitrator: 16 Dec, 2006 - 04:54 AM
User is offlineProfile CardPM
+Quote Post

bazookatooth
RE: Css -- Using Absolute Positioning AND Aligning In Center Of Page
16 Dec, 2006 - 05:57 PM
Post #7

D.I.C Head
**

Joined: 25 Oct, 2006
Posts: 56


My Contributions
Thanks, man... I really appreciate it. I'll post again after i figure out what's wrong and get it working.


QUOTE(Arbitrator @ 16 Dec, 2006 - 05:53 AM) *

You can absolutely position elements relative to a container element instead of the viewport by surrounding all of the absolutely positioned content with a relatively positioned element. Example:

div#container { position: relative; margin: 0 auto; }

With that, you can set dimensions on and center the container element and all of your absolutely positioned content inside of it will be absolutely positioned relative to the div#container element (instead of the viewport).

Note that you DO need to set the dimensions since they will effectively be zero by zero because absolutely positioned content is removed from the normal document flow and the container element will thus not take into account all of the elements it “contains” to define its dimensions dynamically...............

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/8/09 09:18PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month