Embed an iframe that occupies the entire page, all without the use of

I am facing a challenge with an iframe on my webpage, as it appears in letterbox shape. My goal is to make it fill the page vertically while maintaining the horizontal size at 60% with sidebars on the left and right.

Currently, I have achieved this in Chrome but not in Firefox. My aim is for it to work seamlessly across all modern browsers without relying on JavaScript.

The CSS code that works in Chrome but not in Firefox:

iframe, .menu, .main{
   height: 100%;
}

A quick fix using CSS which is dependent on screen size:

iframe, .menu, .main{
   height: 100em;
}

Here is the HTML structure of the page:

<!DOCTYPE HTML >
<html>
  <head>
    <meta charset="utf-8"> 
    <title></title>
    <link rel="stylesheet" type="text/css" href="style/s.css"/>
  </head>

  <body>
    <header>
      <h1></h1>      
    </header>

    <div class="group">

      <div class="menu">
        <iframe src="menu">
          Your user agent does not support frames or is currently configured not to display frames. However, you may visit
          <a href="menu">the index here</a>
        </iframe>
      </div>

      <div class="main">
        <iframe src="main">
          Your user agent does not support frames or is currently configured not to display frames. However, you may visit
          <a href="main">the content here</a>
        </iframe>   
      </div>

      <aside>
        <p>hello side</p>
      </aside>

    </div>

    <footer>
      <p>hello footer</p>      
    </footer>
  </body> 
</html>

And here is the CSS styling applied to the page:

/*background colour*/

header,
.menu,
.main,
section,
aside,
footer {
    background-color: #eee;
    border: 1px solid #888; 
}

/*layout*/

footer {
    clear: both;
}

header,
footer {
    padding: 0;
    width: 100%;
}


.menu,
.main,
section
aside
footer {
    padding: 0;
    margin: 0;
}

body,
.group {
    margin-top: 0;
    margin-bottom: 0;
}

iframe {
    width : 100%;
    border: 0;
}

iframe, .menu, .main {
   height: 100%; 
}

.group:before,
.group:after {
  content: "";
  display: table;
}
.group:after {
  clear: both;
}
.group {
  clear: both;
  *zoom: 1;
}

/*default*/
/*side at bottom on non wide screen*/
aside {
    clear: both; 
}

/*if wide enough put menu on left side*/
@media all and (min-width: 1040px) {
    .menu {
        width: 24.9%;
        float: left; 
    }

    .main,
    section {
        width: 75%; 
        float: left; 
    }
}

/*wide screen — all side by side*/
@media all and (min-width: 1200px) {

    .menu {
        width: 17%;
    float: left
    }

    .main,
    section {
        width: 64%;
    float: left;
    }

    aside {
        width: 17%;
        clear: none;
        float: right; 
    }
}

Answer №1

Finally, CSS now supports the use of vh (viewport height). Also check out vw, vmax, vmin.

Below is an example that utilizes the new CSS grid. CSS flex should also work.

<html>
  <head>
    <meta charset="utf-8">
    <link rel="stylesheet" type="text/css" href="iframe-layout-exp.css"/>
  </head>
  <body class="wrapper">
    <header class="box">Header — this is a header</header>

    <main>
      <iframe src="http://bookmarkdb/">
        What? No iframes.
      </iframe>
    </main>
    <nav class="box">
      Menubar — This is a menu bar
    </nav>
    <aside class="box">Sidebar  — this is a sidebar</aside>

    <footer class="box">Footer — this is the footer</footer>

  </body>
</html>

Notice how simple the HTML structure is, with no unnecessary divs. It cleanly defines the page's semantics with elements in logical order.

/*******************************/
/*Layout*/

nav      {grid-area: sidebar; }
aside    {grid-area: sidebar2;}
main     {grid-area: content;}
header   {grid-area: header;}
footer   {grid-area: footer;}

html, body, .wrapper, main{
    margin: 0;
    padding: 0;
}

.wrapper {
  height: 100vh;
}
.wrapper {
    display: grid;
    grid-gap: 10px;
    grid-template-columns: 120px auto 120px;
    grid-template-rows: min-content auto min-content;
    grid-template-areas:
        "header  header header"
        "sidebar content sidebar2"
        "sidebar footer footer";
}

main {
    display:grid;
}

/*******************************/
/*style*/

.box {
  border-radius: 5px;
  padding: 10px;
  font-size: 150%;
}

header, footer {
  background-color: #999;
}

nav, aside {
  background-color: #ccc;
}

And there you have it, the corresponding CSS code.

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 could be causing the absence of the box within the div element?

I am still learning the ropes of javascript, CSS, HTML and programming in general. Despite being a beginner, I have managed to grasp the basics of simple HTML and CSS. I had successfully created a nested div structure before, but suddenly the inner div is ...

Tips for creating multiple diagonal lines with CSS and HTML

Is there a way to create multiple diagonal lines within a rectangle using CSS and HTML from the start? I am interested in incorporating diagonal lines at the onset of the rectangle. Here is an example code that displays the rectangle: <div className={ ...

Positioning buttons and elements on top of a BootstrapVue Carousel slide: a handy guide

Can different elements be positioned on the BootstrapVue Carousel slide without restrictions, such as in any corner or position? I have attempted to accomplish this by nesting additional elements within <b-carousel-slide></b-carousel-slide> ...

What is the best way to adjust the sizing of Bootstrap columns according to different screen sizes?

I am looking to display 6 items on a webpage... When viewing on a cell phone (xs), I want two rows of three items to display. On larger screen sizes, I would like to see all six items on the same row. I attempted to achieve this using the following code: ...

What is the best way to locate an item reference for a specific DOM element?

Imagine a vast DOM structure with approximately 10,000 HTML elements, including 1,000 span tags. None of the span elements have any identifiers and are buried deep within other objects with long, complex Xpath paths that are not user-friendly for selectio ...

What is the best way to incorporate multiple modals onto a website?

Currently, I am immersed in the world of blog designing and facing a challenge with creating multiple modals. It is my strong belief that Modals should be clearly defined in Javascript. // Accessing the modal element var modal = document.getElementById( ...

Achieving a continuous 2-layer css parallax background in Firefox using css properties "transform" and "perspective" while ensuring the background remains visible beyond content height

You are my final hope. I made a decision to add an update to the Page of my brother's store. One of the new features I wanted was a simple parallax background with two layers to create a sense of depth while scrolling. At first, I managed to make it ...

Is it possible to create a sticky element that stays fixed to the window without using JavaScript?

Using position: sticky has been a game-changer for me. It resolves many issues without the need for JavaScript. However, I've encountered a roadblock. I am trying to create a sticky element that is nested inside multiple <div> elements. Since po ...

How can I retrieve the CSS style value within the C# code behind?

When working with ASP.NET code behind, I often find myself adding a css style to an element using the following command: elementID.Style.Add("padding", "20px"); However, once this css property is added to elementID, the question arises - how can I access ...

The Benefits of Semantic Class Names compared to Microdata

As I strive to use semantic class names, my exploration of microdata and SEO raises a question: Is it necessary to use both? Compare these two HTML snippets representing an event: Using CSS classes: <div class="event" itemscope itemtype="http://schema ...

Creating a left sidebar with a menu that appears after clicking an icon in Bootstrap 4

Check out this example photo sidebar Currently seeking a solution to create a sidebar similar to the one shown in the image above. View photo2 for reference When you click on the sidebar icon, a menu will be displayed. I already have something similar ...

A guide on dynamically adjusting text size based on viewport width and height in React with TailwindCSS

Utilizing React and Tailwind, I am working towards creating two overlapping rectangles with text. The top rectangle's text should be aligned to the left, while the bottom rectangle's text should be aligned to the right. Regardless of window size ...

Find the div element that wraps around the currently selected radio button

Take a look at this code snippet: <div class="paymentOption"> <input type="radio" name="paymentOption" value="1" /> <span class="marginLeft10">1-time payment using a different credit card</span> </div> Is it feasible ...

The HTML page failed to load the bootstrap.min.css stylesheet

I am currently working on a project using Java with Spring Boot in IntelliJ IDEA, managed by Maven. However, I am facing an issue when trying to connect bootstrap.min.css on my HTML page. This problem seems to appear randomly without any clear cause. Inte ...

Click on the image to resize the div accordingly

I have a scenario where I need to achieve the following functionality: Two divs are present, with an image inside the first div. When the image is clicked, the left div should resize, and the content on the right side should expand to show full page cont ...

Can jQuery Alignment be Adjusted Based on the Size of the Browser Window?

After browsing through several websites, I managed to create a basic pop-up box using javascript to showcase my contact details. While I am content with its functionality, I have encountered an issue where the popup window is positioned absolutely rather t ...

Expanding child elements to fit parent container using CSS

Currently, I am attempting to make list items stretch across a list. The following code is relevant for this issue: #navbar ul { list-style-type: none; margin: 0; padding: 0; width: 100%; } #navbar li { display: inline; float: ...

Fuzzy text on the web browser, Internet Explorer

After analyzing my website, I have observed a significant contrast in text quality when viewed on Firefox, Chrome, and Internet Explorer. While the text appears crisp and clear in Chrome and even more so in Firefox, it seems to be blurred and lacking focus ...

Is it possible to use CSS to create a gap between the cursor and the placeholder text within an input field?

Could you please assist me with a bug I have encountered on an older version of Firefox for OSX (37.0.2)? I have included a screenshot of the issue here: https://i.sstatic.net/dzK0G.png Is there a way to use css to move the first character of the placehol ...

CSS Table with Adjacent Single-Cell Row Restricting Multi-Cell Column Width

Hey there! I'm working on designing a website layout using CSS and divs that must meet the following criteria: The top and bottom elements should take up 100% width The top element should be a single "table-cell" The bottom element needs to be divid ...