Position the iframe at the center of the image for the best display

I'm looking for a way to make my web app appear as if it is on an Android or iPhone device. I've explored various solutions, but they all have their drawbacks. My workaround involves loading the web app in the middle of an iframe, which is then placed within an image of an iPhone to frame it. However, the iframe tends to shift around based on the screen size, so it doesn't always stay centered within the frame.

Here's what I've accomplished so far:

<html>
  <head>
    <meta name="keyword" content="key words, keywords" />
    <meta name="description" content="brief and to the point description of the web page." />
    <meta name="robots" content="all" />

    <style>
      #container {
        position: absolute;
        top: 10%;
        left: 45%;
        width: 367px;
        height: 717px;
        margin-top: -50px;
        margin-left: -75px;
      }
      #browser {
        position: absolute;
        top: 23%;
        left: 46%;
        margin-top: -49px;
        margin-left: -64px;
        border: none;
        overflow: hidden;
      }
    </style>

  </head>
  <body style="background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#C7000D), to(#2E0002))"; ">
    <div id="container"><img src="images/ip4.png" style=""></div>

    <iframe id="browser" src="http://server.com/index.php?id=5" width="320px" height="482px" scrolling="no">
      <p>Your browser does not support iframes.</p>
    </iframe>
  </body>
</html>

Does anyone have a foolproof method to ensure that the iframe is always centered within the image?

See the current results here.

Answer №1

One creative way to enhance your phone image display is by dividing it into three separate segments using div elements. Assign the top segment as the background image for the first div, the middle segment for the second div, and the bottom segment for the third div. Make sure each div has equal widths, set the height of each div to match its corresponding image segment, and apply margin: 0px auto; to each one. Next, use display: block; to position an iframe absolutely inside the second (middle) div. Lastly, encase all three divs in a single larger container div with a total height equivalent to the combined height of the individual divs. To align this large div in the center of the page, position it absolutely and adjust the margins accordingly. Don't forget to set your body element's min-width and min-height to accommodate the dimensions of the main div.

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

The image displays successfully on desktop, however, it fails to load once the website is deployed on GitHub or Netlify

While developing this website on my Mac, I encountered an issue where images load fine when I copy the project path from Atom to Chrome. However, once I push the same code to GitHub and then publish it on Netlify, the image fails to load. Does anyone kno ...

What is the best way to make an HTML table with a static header and a scrollable body?

Is there a way to keep the table header fixed while allowing the table body to scroll in an HTML table? Any advice on how to achieve this would be greatly appreciated. Thanks in advance! ...

Steps to Make a White Content Box on Top of an Image Background using HTML/CSS

I am currently struggling with overlaying a white box on top of my background image in order to have my text inside the box for a more visually appealing look. Despite trying to add CSS code like this: .white-box { position: absolute; background-c ...

AngularJS Encounter: A Grand 404 Glitch

Hey, I'm just getting started with AngularJS and following this helpful tutorial. However, I've run into an issue where the $http.get method is consistently giving me a 404 Error when trying to access a JSON file. The JSON file is located in the ...

Tips for managing the PHP cross-protocol problem

I recently started using bootstrap 4 beta for a project. In my HTML file, I have a form with an external JavaScript file linked to it that generates error messages and then points to a PHP file upon success. Additionally, I am utilizing this Bootstrap vali ...

Ensure uniform column width for recurring rows in CSS grid, irrespective of content width

Is there a way to ensure that a CSS grid maintains the same width for repeating rows, even if the content in each cell varies in length? I am attempting to set column 1 to be 10% width, column 2 to be 45% width, and allocate the remaining space to column ...

Optimizing mobile responsiveness for a portfolio landing page

Seeking advice on optimizing my site for mobile view. While the wide-screen monitor display is fine, issues arise when the browser size is reduced, causing sections to appear messy in mobile view. Any suggestions or tips would be greatly appreciated! Visi ...

Position the Twitter, Facebook, and LinkedIn sharing buttons in alignment

I've tried various methods to align the Facebook share button with other social media buttons, but I haven't been successful so far. There seems to be a slight pixel difference. Any suggestions? <div style="float:left; vertical-align:top"> ...

Achieving proper form alignment through Bootstrap

Is there a way to create a form that looks like the one shown in the picture, where regardless of the length of the variable names (Name, Mobile, Gender, Age), all value receiving blocks are the same size and aligned vertically? My initial approach involv ...

employing iframes dynamically to overlay a webpage

I inserted this iframe into a webpage <iframe src='http://redbug.redrocksoftware.com.au:80/Pages/chamara.html' style="position:absolute;z-index:1;" ></iframe> The chamara.html page has a button that, when clicked, should cover the c ...

jQuery: Struggling with removing dynamically generated elements

Hey, I've hit a roadblock with this issue and can't figure out why it's not working. To give you an idea of what I'm trying to do, I've put together a jsfiddle: http://jsfiddle.net/ZNbm8/ This is my jQuery code: var count = 0; $ ...

Vertical alignment of label in the middle of the page is malfunctioning

Check out this fiddle for placing text in the middle of the page vertically. Fiddle HTML: <label class="label"> This text should be centered </label> CSS: .label{ vertical-align: middle; } Despite setting the CSS property, the text is ...

Exploring data in C# using HtmlAgilityPack to extract information from a table

I've been working on a project for some time now, and here's the situation: A friend of mine has a web application that generates data for charts using HTML. I need to extract specific values from a table on his website so that we can store this ...

Is it not feasible to place a well within a column using Bootstrap?

Would like to place a .well div (or a button, whichever works best) within the designated green area shown in this image: here Here is the code I currently have: <div class="container-fluid"> <div class="row row1" style=&q ...

Placing a div tag directly beneath another div tag

Imagine you have a div element with the class name divstudent, let's call this one div1. Now, you want to dynamically create another div element below div1, but outside of it using JavaScript. How can you achieve this? "div1" <div class="divstuden ...

The difference between see-through shades and rgba(0,0,0,0)

What are the primary benefits of using: background-color: rgba(0,0,0,0); over: background-color: transparent; ? ...

Ways to conceal a personalized context menu for right-click operations

I came across a helpful page (How to add a custom right-click menu to a webpage?) discussing "How to add a custom right-click menu to a webpage" The source does not provide any functionality to hide the menu. Any suggestions on how I can hide the menu? ...

Positioning the jQuery mobile navBar to be fixed on iOS 4 devices

Currently working on a mobile app with jquery using iOS4 and iOS5 compatibility as the final hurdle. While fixing the navigation bar is simple on iOS5 with position:fixed, it's not as straightforward on iOS4! I've experimented with various soluti ...

displaying a Google Map within a designated container

I'm currently working on a basic website layout that consists of a full-width banner, a left menu (200px), and right content (600px). I have a simple jQuery script set up to load the content on the right-hand side when any of the five menu items are c ...

Create an input field with a dynamic and exclusive identifier using the DataTables plugin

I am having trouble creating unique IDs for each input field based on the number of rows Here is the code snippet: $(document).ready(function() { var oTable = $('#jsontable').dataTable(); //Initialize the datatable $.ajax({ url ...