Cef
Cef

Reputation: 929

Prevent iframe from resizing when content changes

I have an iframe inside of a table cell, roughly:

<table>
  <tr>
    <td>
       <iframe style=height:100%; width:100% src="content.aspx" />
    </td>
  <tr>
</table>

When the page initially loads everything sizes correctly, the iframe expands to the full area of the cell. If you reload the content of the cell of perform a submit, the iframe collapses, presumably because it thinks there is no content, but then does not re-expand once the content does load.

Can this be prevented? iframe height = 100% always...

**Update: This is my actual iframe:

<iframe id="frmContent" runat="server" frameborder="0" src="Home.aspx" style="height:100%; width:100%; margin:0; padding:0; display:block" >

I discovered the problem is the display: block, but if I don't use that the iframe renders extra space underneath it that ruins my layout causing an extra scroll bar.

Upvotes: 1

Views: 1741

Answers (1)

Oriol
Oriol

Reputation: 287940

Some problems:

  • You must wrap attribute values in quotes when they contain spaces.
  • The size of an iframe doesn't depend on its content.
  • height: 100% only works in elements that can't increase parent's height, that is, those out of the normal flow of the document (absolute or fixed positioned), or those whose parent has a given height (not auto).

Upvotes: 1

Related Questions