PDA

View Full Version : iFrame positioning...


kakshmire
04-25-2006, 05:24 PM
hi. anyone got any ideas how to have an iframe centred on a page but also get its absolute position to be top:0px? i can do one or the other but not both at the same time.

i think i got it together once, but it was centered to the left side of the iframe and not the centre. sorry, for my poor explanatoin, any help would be greatly appreciated.

mlseim
04-25-2006, 06:28 PM
Are you talking about centering an image vertically and horizontally
inside of an <iframe>?

I don't quite understand the question.

kakshmire
04-25-2006, 11:06 PM
i need it centered horizontally but at the very top vertically, with no gap between the top of the iframe and the top of the page.

mlseim
04-26-2006, 02:02 AM
I know of a method that uses PHP.

Are you able to use PHP and can you change the
file extension from .html to .php?

Here's the PHP method for those looking in:

This is the <iframe> tag in your webpage:
<iframe name='frame1' src='center.php?image=./images/myimage.jpg' frameborder='0' scrolling='no' width='425' height='390' style="border: 1px solid #727272;"></iframe>


This is the PHP script that is called "center.php":
<?php

$image = $_GET['image'];

echo "<html>";
echo "<head>
<style type='text/css'>
html, body {
margin: auto;
}
.wraptocenter {
display: table-cell;
text-align: center;
vertical-align: middle;
width: 425px;
height: 390px;
}
.wraptocenter * {
vertical-align: middle;
}
/*\*//*/
.wraptocenter {
display: block;
}
.wraptocenter span {
display: inline-block;
height: 100%;
width: 1px;
}
/**/
</style>
<!--[if IE]><style>
.wraptocenter span {
display: inline-block;
height: 100%;
}
</style><![endif]-->

</head>";
echo "<body>";
echo "<div class='wraptocenter'><span></span><img src='$image' alt=''></div>";
echo "</body></html>";

?>

The key thing is to match the width and height numbers in the <iframe>
with the values in the "center.php" script.

In kakshmire's case, the horizontal centering can remain, but the vertical
centering must be turned off ... I'm guessing you would comment out the
"vertical-align: middle;" lines.

Here's an example of the script in real-life action:
http://www.emilykimball.com/sculpture.php



.

kakshmire
04-26-2006, 02:44 AM
how would i change that to display another page in the iframe?

mlseim
04-26-2006, 04:10 AM
oh, I thought you wanted to place an image inside the <iframe>...

Placing a page (as in a webpage) within the iframe?

or

Placing an iframe within the page?

I'm kind of confused now. Maybe you could give us a link to
what you have so far. I think I was getting it wrong from the beginning:rolleyes:

kakshmire
04-26-2006, 03:09 PM
i want a page inside an iframe, with the iframe centered horizontally and at the very top of the page vertically. thanks for your help so far :)

mlseim
04-26-2006, 04:07 PM
Do you have a link to what you have so far?

I think it can be done with CSS ... but need to see what you have.

cryonic
04-26-2006, 06:48 PM
Will this help?

inside body



<div id="wrapper">

<iframe id="inlineframe" name="iframe"
height="500" width="500"
src="imanemptypage.htm" </iframe>

</div>



inside css



body {
margin : 0px;
}

#wrapper {
position : absolute;
left : 50%;
margin-left : -250px;
width : 500px;
height : 500px;
}

kakshmire
04-27-2006, 12:44 PM
hey thanks. that worked perfectly :D i had been thinking there might be a way to sorta centre it - half the width of the iframe but didnt have a clue how. hehe. many thanks :D