Sun, 2003-06-22 06:48
Is there a way to position a inline-frame to be centered verticaly and horizontaly. please HELP!
Sun, 2003-06-22 08:20
#1
positioning inline-frames! HELP!
Hi Chris,
Not as simple a task as it should be.
Here is couple of things you could try:
Firstly you will need to set the display of the div to block or wrap the iframe in a div.
Then to center it horizontally you can use margin-left:auto and margin-right:auto as long as you know the width.
Unfortunately margin-top and margin-bottom set to auto would be way to easy, so the browsers have made it more chalanging for you.
What I would do is use margin-top set to a specific value or % and be happy that it's close to the center in most browsers.
You could use the magic of Dhtml to verticaly center it.
function vertcenter(x){ var x=document.getElementById(x); var h=x.style.height; var sch=screen.availHeight; var dt= (sch-h)/4; x.style.marginTop=dt+"px"; }
div#theid{ margin-left:auto; margin-right:auto; width:300px; height:300px; margin-top:0; margin-bottom:0;}
<body onload="javascript:vertcenter('theid');"> <div id="theid"> <iframe src="sitecheck12.html" width="300px" height="300px"></iframe></div>