Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Vertical align no table

Status
Not open for further replies.

mcvdmvs

Technical User
Sep 18, 2000
172
NL
Hi all,

I would like to vertically align a div on the page, so it's exactly centered. But I can't get it to work. I don't want to use a table.
vertical-align isn't working either, i guess because the browser don't knows the heigth of the page.

mcvdmvs
"It never hurts to help" -- Eek the Cat
 
I used margins at 50%, auto etc.

However it seems that 10% is the correct margin. That wonders me so much, that i am afraid to use it.

I did some nesting as well, but after three nested divs i conclude that it isn't possible as well. So maybe only the following js sollutions helps:
Code:
// align content in middle
function vertical_align(id) {
	div_content = document.getElementById('content');
	diff = this.height - 600;
	margin = diff / 2;

	div_content.style.marginTop = margin;
}

mcvdmvs
"It never hurts to help" -- Eek the Cat
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top