CSS Help - Aligning DIVS etc

Associate
Joined
24 Sep 2005
Posts
209
I wish to create a "webpage" interface which will be 750px x 350px in size.

How would I align the content so that it is fully centred within the browser window, regardless of whether someone is browsing at 1024x768 or 800x400? At the mo I've set it up using percentages & absolute positioning but when the screen resolution changes, the webpage appearance is distorted.

Is there a way of automatically centering everything both horizontally and vertically and expanding content outwards from the centre?

Thanks
 
Soldato
Joined
12 Jan 2004
Posts
3,172
Location
Brighton
PHP:
#verticalCentre
	{
	text-align: center;
	position: absolute;
	left: 0px;
	width: 100%;
	height: 1px;
	top : 50%;
	overflow: visible;
	visibility: visible;
	display: block
}
#horizontalCentre
	{
	margin-left: -XXX px;        // Where XXX = 1/2 x width of your page
	margin-top: -XXX px;        // Where XXX = 1/2 x height of your page
	position: absolute;
	left: 50%;
	width: XXX px;                // Where XXX = your page width
	height: XXX px;               // Where XXX = your page height
	visibility: visible;
}

OH GOOD GOD someone from admin sort out the colour of code of the PHP tag :S

It should take about two seconds :S

EDIT : Forgot to add, put into the html body

<div id="verticalCentre">
<div id="horizontalCentre">
Your content goes here
</div>
</div>
 
Last edited:
Associate
Joined
20 Aug 2003
Posts
2,446
Location
London
Assuming you have all your div's in a container div then try this

Code:
body {
	text-align: center;   // older IE fix to align content in the middle
	padding: 0;
	margin: 0;
	}
#container {
	text-align: left;    //text is set to align left. 
	margin-left: auto;
	margin-right: auto;
	}
 
Last edited:
Soldato
Joined
12 Jan 2004
Posts
3,172
Location
Brighton
nolimit said:
Assuming you have all your div's in a container div then try this

Code:
body {
	text-align: center;   // older IE fix to align content in the middle
	padding: 0;
	margin: 0;
	}
#container {
	text-align: left;    //text is set to align left. 
	padding: 0;
	margin: 0;
	}

That won't centre it vertically.
 
Back
Top Bottom