Create an iframe that spans the entire width of its containing element

I am struggling to make this iframe fill 100% of its parent div, which has a width of 900px. The current code is not achieving the desired result.

Here is the HTML:

<fieldset>
  <legend>Random Patch:</legend>
  <iframe src="../../index.php?Patch_No='.$patches[$patch].'" frameborder="0" ></iframe>
</fieldset>';

In the CSS update, I tried setting the width of the iframe to 100%, but it didn't work as expected. Here is how it appears: https://i.sstatic.net/9cBw7.png

iframe {
   width: 100%;
   height: 500px;
}

Update 2 with the complete HTML:

<body>
    <div id="wrapper">
        <header>
            <div id="menu"> <a href="new_patch/new_champions.php" id="new">NEW</a>
                <!-- Editing patches still in works href="edit_patch.php" -->
                <a id="edit" style="color: grey;" alt="Edit" title="Disabled still in works.">EDIT</a>
                <a href="delete_patch.php" id="delete">DELETE</a>
                <a href="logout.php" id="logout">LOGOUT</a>
            </div>
        </header>
        <div id="sitelive">
            <?php
            //Generating random patch from DB
            $sql="SELECT Patch_No FROM info";
            $result=$ conn->query($sql);
            $patches=$result->num_rows;
            if($patches!=0) {
                $patch = rand(1, $patches);
                $i = 1;
                $patches = array();
                while($data=$result->fetch_assoc()){
                    $patches[$i] = $data['Patch_No'];
                    $i+=1;
                }
                echo '
                <fieldset>
                    <legend>Random Patch:</legend>
                    <iframe src="../../index.php?Patch_No='.$patches[$patch].'" frameborder="0" height="500" width="100%" scrolling="no"></iframe>
                </fieldset>';
            } ?>
        </div>
    </div>
</body>

Answer №1

Make a simple adjustment to your CSS code: See Updated Demo

iframe {
    width:100%;
    height:500px;
}
fieldset, legend {
    margin:0;
    padding:0;
    width:100%;
    height:100%;
}

Here is the HTML code snippet:

<fieldset>
    <legend>Random Patch:</legend>
    <iframe src="../../index.php?Patch_No='.$patches[$patch].'" frameborder="0"></iframe>
</fieldset>

I hope this modification meets your requirements.

Answer №2

It appears that there is an issue with your CSS syntax.

Try using the following code snippet to fix it:

section {
  margin:0 auto;
  padding:20px;
}

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

How can I apply bold styling to my interpolation binding in Angular while working on my HTML code?

Below is the code snippet where I am attempting to highlight profile.userId: <p class="profile__last-login" *ngIf="profile.lastLoggedIn"> {{'intranet.profile.dashboard.lastLoggedIn' | messageBundle: profile.userId + ',' + (pr ...

Error: Unexpected syntax error encountered in the form of T_FOR

I'm currently working on building an HTML form that includes a dropdown menu. Check out the code snippet I have below: $output[]='<td><select name="qty'.$name.'">' for($count=1;$count<=$total;$count+=1) { &apo ...

Accessing the id within both objects is proving to be a challenge for me

I'm facing an issue with accessing and posting values of the id within Position and Department in Angular. It seems like the id is not being accessed correctly. addEmployee.model.ts export class AddEmployee { Position: { id: string; }; De ...

What is the best way to reduce the width of the preformatted tag?

Is there a way to adjust the width of the pre tag in order to avoid affecting the q-card when resizing the browser window? I am trying to create a q-card that can display code similar to what you see in ChatGPT. However, the q-card's size is not respo ...

Steps to switch the displayed ionicon when the menu is toggled

My goal is to display the 'menu-outline' ionicon on my website until it is clicked, at which point the icon will change to 'close-outline' and vice versa. I am utilizing jQuery for this functionality. Although I am aware of how to togg ...

Two DIV elements are merging together with a cool zooming effect

As a beginner in using Bootstrap 4, I am working on creating a practice website. While designing the layout, I encountered an issue that seems simple but I can't seem to figure it out. <div id="box-container" class="container-fluid"> &l ...

Are web components capable of managing changes in CSS (maybe through cssChangedCallback)?

Is there a way to control the application of CSS to a web component similar to using attributes through attributeChangedCallback. I am currently developing a couple of web components that could benefit from being styled with CSS classes. However, I requir ...

Django: Troubleshooting problem with offcanvas PDF preview iterations

Hey everyone! I'm in the process of creating a webpage that features a table with metadata regarding PDF files. To enhance user experience, I want to provide users with a preview of stored files in an off-canvas format. This is my HTML file setup: & ...

Locate the target item that shares the identical class

My goal is to achieve the following: When I click on a month #month > li >a, it should fade in the list with the class name of that month and hide the other month lists so only one is shown. While this may sound simple, I am unsure of the correct jQu ...

Transform CSS into React styling syntax

I am having trouble converting CSS code from an HTML template for text input into a React project. I am not a CSS expert, and I am encountering some syntax errors. Can someone help me fix this issue? I have included the CSS code, app.js file, and error ima ...

Creating grid columns with evenly distributed widths that match the maximum width of the content within the items

Within a container grid, I have a variable number of child items with different widths. I am looking to use CSS grid to arrange them so that each column has equal width. The width of each column should be based on the widest child item. My initial approa ...

Issue with uploading files in Internet Explorer using Ajax not resolved

I've been encountering an issue while uploading images using Ajax and PHP. Surprisingly, everything runs smoothly on Firefox but fails to work on Internet Explorer (I.E). Take a look at my HTML code below: <!doctype html> <head> <titl ...

Tips for aligning the list style icon perfectly with the text

I need help aligning text in the center of a customer list style image for an LI element. I've attempted using margins and paddings, but it hasn't worked. Here's the code and screenshot: HTML: <ul class="homeList"> <li>Over ...

Can AngularJS support HTML5-mode URL routing in locally stored files (using the file:// protocol)?

Sorry if this question has already been asked, but I haven't been able to find any information on it. I'm working on an AngularJS application that needs to be accessed directly from a hard drive (not through a traditional HTTP server), so the UR ...

The art of controlling iframe elements with jquery

I've been researching various topics related to this issue, but I'm still unable to achieve the desired outcome. Currently, I am embedding an iframe within an HTML document like so: <iframe class="full-screen-preview__frame" id="nitseditpre ...

Progress Bar Aligned in the Middle

I am having difficulty centering the percentage total within the colored progress bar. I have attempted placing the <p> tag in various <div> tags but haven't been able to figure it out. Can someone provide assistance? ...

Animating margins and padding using CSS transitions can result in a choppy and inconsistent animation effect

On my personal website, I have implemented the CSS3 Transition property on the top navigation to create an animation effect on an element with a border. This effect causes the border to swell when hovered over. Here is the relevant markup: <nav> ...

Troubleshooting display issues with Chrome and Opera due to jQuery CSS interactions

I am looking to implement a feature where a floating text message appears when the user clicks on certain HTML elements. Here is the code snippet: function showAlert(el, e){ var y = e.pageY; var x = e.pageX; savedState = classes[classes.len ...

Tips for setting up a hierarchical mat-table within a parent table that supports expandable rows using Angular Material

Here is the data that I am working with: [ { "_id": "c9d5ab1a", "subdomain": "wing", "domain": "aircraft", "part_id": "c9d5ab1a", "info.mimetype": "application/json", "info.dependent": "parent", ...

Encountered a problem while trying to update a list item in Vue.js

Greetings Everyone, I've successfully implemented a basic CRUD functionality in VueJS. The values are being inserted into a list, from which I can read and delete them. However, I'm facing an issue with updating any value. When I try to ...