...

View Full Version : CSS: positioning at center/middle of screen



Zvona
12-17-2002, 07:37 AM
I'm struggling with a problem of how to write valid CSS and XHTML, which would position object (div) center of the screen (both vertically and horizontally). This should be done with CSS and should work in modern browsers (IE5+,NS6+/Moz0.9+, Opera6+).

Currently, positioning is done with JS :
http://www24.brinkster.com/zvona/saunaseura/jasenhakemus.html

krycek
12-17-2002, 01:23 PM
if you don't mind using position: absolute, then the following may help you:



#frame {
width: 640px;
height: 480px;
margin: auto;
padding: 0px;
}


It is adapted from a technique at glish.com (http://glish.com/css/3.asp) and I believe it should work... not sure if it will work if the dimensions are not specified explicitly.

Also if you don't want to use position: absolute, then I *think* you could use a div with text-align: center and then put another div inside, with the vertical-align set to middle, however vertical-align hardly ever works properly for me and I cannot guarantee that this approach will work.

Hope that helps... it may give you some ideas if nothing else :)

::] krycek [::

beetle
12-17-2002, 04:35 PM
Here (http://www.peterbailey.net/dhtml/centered.htm) is a method that works :D

krycek
12-17-2002, 04:48 PM
Originally posted by beetle
Here (http://www.peterbailey.net/dhtml/centered.htm) is a method that works :D

heheh, I do believe that is exactly the same as my method, except you have put it into a page :) lol

::] krycek [::

beetle
12-17-2002, 07:20 PM
Nope. margin: auto; won't handle vertical centering.

krycek
12-17-2002, 09:46 PM
damn :(

ah well I tried - albeit very quickly and I didn;t test it lol :p

::] krycek [::

Zvona
12-18-2002, 08:26 AM
Originally posted by beetle
Here (http://www.peterbailey.net/dhtml/centered.htm) is a method that works :D

Well, thank you. With minor modifications it started working properly. Although only few end-users have JS disabled, I prefer using CSS for positioning.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum