Adjusting Iframe to Fit Entire Screen Using CSS

I've been working on making an iframe adjust to fit the screen size, regardless of the user's resolution. However, no matter what I do, I can't seem to get it just right. It always ends up either too small or with a double scroll bar issue (both for the iframe and the page).

My goal is to have the iframe occupy 85% of the page's width (which is working fine), be positioned 100px from the top of the screen (also achieved), and then seamlessly reach the bottom edge of the browser window (struggling with this part...)

HTML

<div id="maindiv" class="maindiv">
<iframe id="theiframe" class="iframeautowidth" seamless src="http://whateverdomain.com></iframe>
</div>

CSS:

.maindiv {
width: 85%; 
top: 100px;
}

.iframeautowidth {
left: 0px;
top: 0px;
bottom: 0px;
width: 85%;
height: 100%;
border: 0
overflow: hidden;
display: block;
margin: 0;
float: left;
}

If it helps, I also have the latest version of jQuery running on my page. Any assistance would be greatly appreciated! Thank you!

Answer №1

Utilize the onload() event of your iframe along with the onresize() event of the window to dynamically adjust the size of the iframe as needed.

This informative article from Microsoft Support provides a detailed explanation.

Just a heads up, in javascript, using screen.width and screen.height will allow you to access the screen resolution.

Answer №2

Imagine the possibilities with Fx4, where a mere height: -moz-calc(100%-100px) could perform magic. It's unfortunate that such a useful feature was only introduced and supported in the later stages of CSS3.

Answer №3

In the event that the 100px top is designated for tabs used in navigating the iframe, there could be a possible solution. Consider filling your iframe with a height of 100% and placing those tabs within the iframes as another iframe with a set size. Alternatively, you could opt for using framesets.

Whether this method proves effective depends on the specific design you have, but hopefully it provides some assistance.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is your preferred method for adjusting the size of Divs on your webpage according to the screen size?

Currently working on a coding test and facing an issue with the display of div sizes across different screens. The discrepancy in appearance between my laptop and a Mac computer monitor is causing some trouble, as on my small laptop the divs appear overs ...

form field with the ability to select multiple files

From my understanding, traditional html or javascript do not have the capability to upload multiple files (images) in a singular field. Please correct me if I am mistaken. Is there a way for this to be achieved with html5 or any other method aside from us ...

Width and left values don't play well with absolute positioning

I am encountering an issue where a div with absolute positioning, which is a child of another absolute positioned element, is not behaving as expected. Despite setting width:100%; left:1px; right:1px on the child element, it extends beyond its parent. < ...

HTML elements generated dynamically do not possess any jQuery properties

I have implemented a draggable list of Div elements using jQuery. Here is the code: <div id="external-events"> <h4>List Of Staffs</h4> <div class="external-event" data-id="1">Name</div> //Draggab ...

When using @RestController in the following code, the HTML file is not being returned properly in the REST API. Instead, only the file name such as 'index' is displayed on the screen

Having trouble getting the HTML file to return in the Rest API. Only returning the file name like 'index' when using @RestController, but works fine with @Controller. I am working on a Spring Boot REST application and utilizing index.html with Bo ...

Is there a way to retrieve the data inputted into dynamically generated input boxes and send it to the controller using jQuery?

I am working on a form that allows users to enter input boxes and remove them with a click. I need help extracting the values entered in these input boxes and passing them to a controller using jQuery. Currently, I am using ids to extract the values but I ...

Issue with Jquery .scroll method not triggering display:none functionality

Styling Using CSS #acc-close-all, #to-top { position: relative; left: 951px; width: 29px; height: 42px; margin-bottom: 2px; display:none; } #acc-close-all a, #to-top a { position: absolute; float: right; display: block ...

The showdown between AngularJS Directive Restrict A and E

In our small team, we are currently working on a project in AngularJS and striving to uphold basic standards and best practices. Since we are still relatively new to Angular, we have some questions regarding Directives, specifically the `restrict` options. ...

Struggling with CSS due to the INCLUDE Function

After downloading a Template + CSS File for the website I am working on, everything was going smoothly until I decided to break down the template into separate files for easier modification and editing in the future. However, once I cut out the head sectio ...

When the hover effect is triggered, the background animation smoothly resets back to its initial position once the

I have a picture with a clear background that I want to add a CSS3 background animation to when the mouse hovers over it. Here is the CSS code I am currently using: @keyframes in { from {background-color: #fff;} to {background-color: #900;} } @-webkit-k ...

Immersive full-screen YouTube video embedded as hero background

Seeking a solution in HTML & CSS to display this embedded video as a 75vh height hero background. Currently, the iFrame maintains its width: 100% and height: 75vh, but the images themselves do not cover the entire header width. Essentially, I want it ...

Rotating 3D cube with CSS, adjusting height during transition

I'm attempting to create a basic 2-sided cube rotation. Following the rotation, my goal is to click on one of the sides and have its height increase. However, I've run into an issue where the transition occurs from the middle instead of from the ...

Unable to conceal with Bootstrap collapse

Having trouble collapsing the bootstrap <a href="#demo" data-toggle="collapse">Expand/Collapse</a> <div id="demo" class="collapse"> @item.Ans </div ...

JavaScript button with an event listener to enable sorting functionality

I am looking to implement a button that will reset all the filters on my page. Any ideas? Currently, I have multiple radio buttons for filtering items based on price, size, and color. My goal is to create a reset button that will remove all filters and r ...

Modify the text in a paragraph by clicking on a link using JQuery and HTML

I'm attempting to implement a straightforward action, but I'm facing some challenges. My navigation bar consists of a few links followed by a text section. What I aim for is that when I click on a link, the paragraph of text should change to refl ...

HTML - Automated Navigation to Anchor Links

My website features a search box and various options. While the mobile version displays these prominently on the start page, once a user performs a search, the result page also includes the search box and options at the top. To streamline the user experie ...

The dropdown menu is unable to open directly below the main menu item

How can I make the submenu open to the left when hovering over a menu point, instead of directly under it? I have tried adjusting the position attributes but haven't found the right solution yet. The closest I got was by changing the display property ...

Solving the enigma of CSS positioning: mastering floats, margin-left/right, and auto

Hey there, I'm having trouble posting an image but here is the link: I believe this explanation will be clearer, D2, D3 & D4 need to be aligned next to each other and centered on the screen at all times. (960px)      & ...

Customizable Designs in Oracle Application Express version 4.2

In my work supporting the organization, I am using APEX 4.2 to create a Training Calendar. While I am not a DBA or programming expert, I have been learning through trial and error. The calendar is already set up, but I am looking for a way to customize ho ...

Tips for aligning specific items to the right side of the navigation bar

I've been grappling with creating a navigation bar for a website, aiming to position 4 elements on the left side of the screen and 2 on the right. Despite knowing that there's likely a straightforward solution, I'm struggling to get the elem ...