The height of the body remains constant regardless of the amount of content it contains

My issue arises from the fact that my body height does not adjust to the content inside the iframes when using Javascript. Each iframe contains different content and heights, causing gaps in the layout if one iframe is smaller than the others. Is there a way to resolve this inconsistency?

body {
width:500px;
height: fit-content;
block-size: fit-content;
}
.myDiv {
background-color: lightblue; 
text-align: center;
border-radius: 20px;
max-width: 500px;
align-content: center;
margin: auto;
}
iframe{
overflow:hidden;
display:block;
width:100%;
border:0; 
}
<div class="myDiv">
    <iframe src="1.html" name="one" width="300px" title="Iframe main" scrolling="no" ID="target"></iframe>
   
<a href="content1.html" target="one">01</a><br>
<a href="content2.html" target="one">02</a><br>
<a href="content3.html" target="one">03</a>
</div>
<script>
var div = document.getElementById("target");
div.onload = function() {
    div.style.height = div.contentWindow.document.body.scrollHeight + 'px';
}
</script>

Answer №1

It appears that the issue lies with your CSS not functioning correctly.

body {
width:500px
height: fit-content
block-size: fit-content
    }

Make sure to include semi-colons like so...

body {
width:500px;
height: fit-content;
block-size: fit-content
    }

You have the option to add one to the last item, but it's not a requirement.

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

Troubleshooting problems with connecting Express JS and MongoDB

I've written a simple code to connect express js to mongodb, and I've installed both packages. However, I'm encountering an error. Can someone help me troubleshoot this? const express = require("express"); const app = express(); app.listen( ...

Playing videos using Ionic's ngFor directive allows for dynamic rendering

I'm attempting to initiate the video playback from ts within the ionic component, but it seems like every time I call video.play(), the video is recreated. Here is my HTML code: <video poster=&qu ...

Using jQuery to animate a DIV sliding in from the side

When a user scrolls down (x) pixels, I'm smoothly sliding a DIV into the viewport horizontally. If the user scrolls back up, the DIV scrolls out again. However, the sliding motion appears jerky and pauses at certain moments. <div id="doom_o">&l ...

Tips on disabling unnecessary server validation in ASP.NET

After implementing ValidatorEnable to disable a RequiredFieldValidator using JavaScript, I noticed that on postback the control being validated by the validator is still being validated. This suggests that even though I disabled the validator on the client ...

Webpack 2.7 is experiencing difficulty loading the blueprintjs core CSS

While attempting to utilize blueprintjs and importing its CSS, I believe I may have misconfigured my webpack setup. This resulted in the following error https://i.sstatic.net/eErly.png Below is my webpack configuration: const ExtractTextPlugin = require( ...

Trouble encountered while configuring and executing Electron combined with React, Typescript, and Webpack application

I am currently in the process of migrating my Electron application from ES6 to Typescript. Despite successfully building the dll and main configurations, I encounter a SyntaxError (Unexpected token ...) when attempting to run the application. The project c ...

The slide experiences overflow as it continuously slides up and down

Hey everyone, I've been working on creating a slider effect when a button is clicked. Details about a specific part appear in a designated div upon button click. However, I've encountered a bug where, if I click quickly on different slides, the c ...

Sort by a field other than _id and implement pagination by using the last record's id in Mongod and Node.js

Currently, I am employing three different filters in my code to filter my data. Here is a snippet of the implementation: /* Initialize pipeline */ const pipeline = []; /* All reviews of Auth Host */ pipeline.push({ $mat ...

"Track the progress of a form submission with a loading indicator using Sweet

I am looking to incorporate a waiting time animation when submitting a form, and I prefer using SweetAlert over a traditional loading image. Here is the basic code snippet: $("form").submit(function (e) { e.preventDefault(); // prevents def ...

What could be causing the shadow casting issue with a 3D model in three.js?

I am working with 3D models that are structured like this: https://i.sstatic.net/osXTl.png My goal is to incorporate a cast shadow similar to this: https://i.sstatic.net/DBrRr.png Here is the code snippet responsible for handling the model: var ambLigh ...

What could be the reason for a particular product edit page showing up completely blank?

In my ongoing project, I am developing an admin panel that allows administrators to add new products to their website. These products are then stored in a Firestore database and managed using Redux Toolkit. The added products can be viewed and edited in th ...

PHP SQL JAVASCRIPT SEARCH FUNCTION NOT FUNCTIONING PROPERLY

I'm currently developing a website for a company that includes a search bar to look up customers and employees by their names in the database. The code I have generates an output where only the first name and last name are searchable individually, re ...

What is the best way to save geolocation coordinates in a Javascript array?

I am attempting to utilize HTML5 geolocation to determine a user's location and then store the latitude and longitude coordinates in an array for future use with Google Maps and SQL statements. However, when I attempt to add these coordinates to the a ...

Move a div to line up with a table row when clicked using jQuery

As I mentioned in a previous post, my experience with jQuery is limited and I apologize for that. The task I am attempting to accomplish seems relatively straightforward. Here's an overview of the situation: I have a table enclosed within a div. Each ...

Steps to display a panel containing dynamic content using HTML

When the user clicks on my addon's button in the browser toolbar, I want to display a drop-down menu with dynamic HTML content. The documentation suggests using a panel, but there is a problem. The content may change while the addon is running, and pa ...

Can an array key be a function's return value used in PHP?

I attempted to create a utility function in a rushed manner that I wanted to use as the key for an array, but encountered syntax errors. Is it feasible to insert a function as a key within an array? function generateCustomKey(attr, value) { return &a ...

Hugo: Enhancing text block aesthetics without the need for inline HTML styling

Recently, I successfully eliminated all inline HTML from my Hugo blog that was previously utilized to style the images inserted into my posts. By using CSS selectors, I have achieved this so that Markdown syntax like ![](Landscape.jpg#align-left) yields t ...

Determining the best time to utilize AngularJS data binding compared to Rails data binding depends on the

Combining Rails and AngularJS appears to be a promising combination. However, I find myself struggling with the concept of data binding. In AngularJS, data is provided through a scope which then generates content based on that data. On the other hand, my ...

Tips for showcasing a "loading" animation as a lazy-loaded route component loads

Utilizing webpack's code splitting feature, I have divided my application into multiple chunks to prevent the entire bundle from being downloaded at once when a user visits my website. Some routes require large chunks that may take some time to downl ...

Issue with React JS: parent component's setState function is not updating the state of a nested child input field during the onChange event

While working on the code, I encountered an issue where the grandparent component's setState method updates correctly for an onClick event triggered by the grandchild component. However, when it comes to the onChange event, the update is failing with ...