Aligning to center while still using DIV tags

Location of the Videos
User avatar
Zerk
Posts: 58
Joined: Wed Jan 20, 2010 2:59 am

Aligning to center while still using DIV tags

Post by Zerk »

I want the game to be aligned to center, but I still want to be using position:absolute with div tags.

Right now everything is on the left. If I use different positioning, it will only be aligned to center with my resolution. How can I align to center with all resolutions?

This is what my site looks like right now: http://void.webege.com/ (uploaded it so you can look at it :P)
(Please do not register, it hasn't been updated in a long time.)
Coding - Unity3d JS, PHP, and small amount of C#.
Art stuff - GIMP, Blender
User avatar
hallsofvallhalla
Site Admin
Posts: 12026
Joined: Wed Apr 22, 2009 11:29 pm

Re: Aligning to center while still using DIV tags

Post by hallsofvallhalla »

make a div called wrapper and make the margins auto, put your entire site within this wrapper.
User avatar
Zerk
Posts: 58
Joined: Wed Jan 20, 2010 2:59 am

Re: Aligning to center while still using DIV tags

Post by Zerk »

hallsofvallhalla wrote:make a div called wrapper and make the margins auto, put your entire site within this wrapper.
make the margins auto?

use:
margin:auto;
in the style sheet? Never heard of it before, lol

EDIT: hmm...I tried it and it leaves it all on the left. I added "border: 2px solid purple" to see if it surrounds the content and it doesn't. It starts and ends at the top of the page. I can't figure out how to get it to surround the whole page.

EDIT...again...: kept searching other places and found this:

Code: Select all

left: 50%;
width:800px;
margin-left:-400px;
It works :) Thanks for your help, though. :D and thanks for the video tutorials
Coding - Unity3d JS, PHP, and small amount of C#.
Art stuff - GIMP, Blender
User avatar
Torniquet
Posts: 869
Joined: Sun Aug 02, 2009 6:18 am

Re: Aligning to center while still using DIV tags

Post by Torniquet »

Code: Select all

<body>
  <div style="margin-left:auto; margin-right:auto;">
    content here
  </div>
</body>

that should work without any problems.
New Site Coming Soon! Stay tuned :D
User avatar
Zerk
Posts: 58
Joined: Wed Jan 20, 2010 2:59 am

Re: Aligning to center while still using DIV tags

Post by Zerk »

Torniquet wrote:

Code: Select all

<body>
  <div style="margin-left:auto; margin-right:auto;">
    content here
  </div>
</body>

that should work without any problems.
nope..
Coding - Unity3d JS, PHP, and small amount of C#.
Art stuff - GIMP, Blender
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Aligning to center while still using DIV tags

Post by Jackolantern »

Did you get it fixed since this post? When I look at the page you linked above, it appears to be centered properly.
The indelible lord of tl;dr
User avatar
hallsofvallhalla
Site Admin
Posts: 12026
Joined: Wed Apr 22, 2009 11:29 pm

Re: Aligning to center while still using DIV tags

Post by hallsofvallhalla »

looks liek he found an alternative but I would recommend trying it in all browsers and under a few different screen resolutions to make sure it always centers..

Nice job on solving the problem.
User avatar
Zerk
Posts: 58
Joined: Wed Jan 20, 2010 2:59 am

Re: Aligning to center while still using DIV tags

Post by Zerk »

It seems to be working in all browsers in any resolution above 1024x800 (or whatever that middle resolution is).

Under that is centered, but there is unneeded margins on both sides so you have to scroll sideways a bit...hmm
Coding - Unity3d JS, PHP, and small amount of C#.
Art stuff - GIMP, Blender
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Aligning to center while still using DIV tags

Post by Jackolantern »

Zerk wrote:It seems to be working in all browsers in any resolution above 1024x800 (or whatever that middle resolution is).

Under that is centered, but there is unneeded margins on both sides so you have to scroll sideways a bit...hmm
Hmmm...that is definitely a problem in today's world of various devices connecting to the web. Many platforms are using well under that resolution. Maybe it wasn't working before because of some clashing style in the page.
The indelible lord of tl;dr
User avatar
Zerk
Posts: 58
Joined: Wed Jan 20, 2010 2:59 am

Re: Aligning to center while still using DIV tags

Post by Zerk »

Jackolantern wrote:
Zerk wrote:It seems to be working in all browsers in any resolution above 1024x800 (or whatever that middle resolution is).

Under that is centered, but there is unneeded margins on both sides so you have to scroll sideways a bit...hmm
Hmmm...that is definitely a problem in today's world of various devices connecting to the web. Many platforms are using well under that resolution. Maybe it wasn't working before because of some clashing style in the page.
I'll probably keep digging into it.. hmm (for lack of a better thoughtful word)
Coding - Unity3d JS, PHP, and small amount of C#.
Art stuff - GIMP, Blender
Post Reply

Return to “Older Browser MMO Videos”