What is the best way to align the iframe perfectly in the middle of its container following the application of transform: scale and transform: origin?

I want to resize an iframe with my other website inside while keeping it centered. Scaling is working fine, but centering has been a challenge for me.

I've attempted using flex with justify-items: center & align-items: center on the parent element, but the iframe remains stuck in the top left corner. I also tried using margin: auto, but it didn't work as expected. Adding margin-left did shift it slightly. I am puzzled why setting margin: auto wouldn't center it when there's available margin and the parent has 100% width.

Below is the snippet of HTML/JSX:

import './Desktop.css';
import desktopMockup from '../../assets/desktop.png';

const Desktop = ({ site }) => {

    const 

    return (
        <div className="desktop">
            <div className="iframeDesktop">
                <iframe src={site} scrolling="no" title="desktop" width="1920" height="1080"></iframe>
            </div>
            {/* <img src={desktopMockup} alt="desktop mockup" /> */}
        </div>
    );
};

export default Desktop;

And this is the accompanying CSS code:

.desktop {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-items: center;
    align-items: center;
}

.iframeDesktop {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-items:center;
}

iframe {
    position: absolute;
    top: 0;
    right: 0;
    left: 0;
    bottom: 0;
    transform: scale(0.17);
    transform-origin: top left;
    min-width: 1920px;
    min-height: 1080px;
}

https://i.sstatic.net/R9YIH.png

Answer №1

Have you considered using transform-origin: top center; in place of transform-origin: top left;? Perhaps it's worth experimenting with. Would you be willing to test it out?

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

Circular container housing SVG icons next to another container using Bootstrap 4.5

Currently, I am delving into the world of Bootstrap 4.5 and SVG icons. However, I'm facing some challenges in grasping how it all comes together. My goal is to place an SVG inside a rounded-circle shape for now, positioned next to another div. Unfortu ...

Issue with alignment of inline elements

I recently added a more button to my share buttons, sourced from simplesharebuttons.com, with the intention of revealing less popular social media icons on smaller screens. However, I am encountering an issue where the button is not aligning with the rest ...

Determining the container height for every two-image row

I am currently working on a project for this website. My focus right now is on resizing vertical images using the following script: function Gallery(selector) { this.add_module = function (type, image) { var portrait_text = image.next('.portr ...

CSS - the styling properties of the class should not affect the child components

I am working on a Parent component that contains two child components. Each component utilizes accordion-groups for its functionality. I have created a specific class for styling purposes in my stylesheets, but I want this class to only apply to the parent ...

CSS: Breaking free from the constraints of a Bootstrap-inspired grid layout

Looking to create a template with a background on the left side that extends to the edge of the page within an 8 of 12 bootstrap columns setup. The remaining 4 columns on the right will not have a background. This layout should be responsive, stacking on t ...

Animation issue in Material UI autocomplete label feature

Hello, I am currently delving into the world of React and Material UI. I have been working on implementing the Material UI auto complete feature with chip functionality. You can see my progress here: https://codesandbox.io/s/runh6. Everything seems to be w ...

Bootstrap 5 - centering "padding" both internally and externally within the accordion

Need help aligning three Boostrap 5 grids: Header outside of accordion Overview in accordion header Details in accordion body The accordion header has margins and padding on the left and right, and the collapse icon also occupies some space. I want the ...

Arrays in Javascript (correlating)

I'm having trouble figuring out what needs to be included in this code (I apologize that it's in German, it's an array corresponding to images for JavaScript.) function namenZuBildern(){ var bilder = new Array( "000227", "000228", " ...

Modify the class's height by utilizing props

Using Vue 3 and Bootstrap 5, I have a props named number which should receive integers from 1 to 10. My goal is to incorporate the number in my CSS scrollbar class, but so far it's not working as expected. There are no error messages, it just doesn&a ...

Replacing scrollbars of a div using overflow:auto with arrow indicators: A step-by-step guide

Currently, I am in the process of creating a small div element that will enable users to scroll between images within a jquery image zoom plugin designed for an eCommerce website. Below is the code snippet that I have developed thus far: <div style="w ...

What are some strategies for efficiently positioning buttons using CSS to prevent unwanted consequences?

Below is the CSS and HTML code, detailing a specific issue. * { box-sizing: border-box; font-family: Georgia, 'Times New Roman', Times, serif; } body { margin: 0; font-family: Georgia, 'Times New Roman', Times, serif; } .topn ...

The column width in Bootstrap HTML is too excessive

var parentDiv = document.getElementById("cc"); var statementDiv = document.createElement("div"); var statementName = document.createElement("div"); // var removeIconDiv = document.createElement("div"); // removeIconDiv.className = "col w-25"; // ...

Tips on using CSS3 without relying on images

Can the following be designed using only CSS3 without the use of images? ...

How can I create responsive buttons with icons using material-ui?

I'm working with a material-ui Button that has a startIcon, and I need to hide the button text on smaller screens while still showing the icon. One common solution would be to use the useMediaQuery hook to identify the browser size and render a diffe ...

CSS trick for stylish arrow placement on top of a slide

Hey there! This is my first time navigating through the slick carousel functionality. I'm currently facing a challenge with adjusting the positioning of the arrow within the slider. My goal is to have the arrow displayed at the top level just like the ...

What is the best way to add three dots at the end of text when it exceeds the available space?

What CSS property is utilized to display three dots at the end of text when it overflows? ...

What is the best way to wrap a div in a vertical orientation?

I'm looking to create a vertical div around an image that fluidly changes width: |_________________| | |XXXXXX| | | |XXXXXX| | | |XXXXXX| | | |XXXXXX| | | |XXXXXX| | | |XXXXXX| | |-----------------| The cont ...

Tips for showcasing embedded content in WordPress without the need for scrolling

I am in the process of building a website. The sidebar menu contains a list of pages and posts from my WordPress blog. Whenever I select a menu item, the content is displayed within one of the templates I have created in an Iframe. However, there seems to ...

Using Rails to reference an image in CSS

My application on Heroku, built with Rails, features a striking image as the background on the landing page. Since Heroku's file system is read-only, I made the decision to store these images (selected randomly) on AWS S3. In my .css(.scss) code, the ...

background gradient coloring and image blending

I have created a special class that includes a gradient background color: .banner { background: -moz-linear-gradient(center top , #75A319 0%, #9FCC1D 100%) repeat scroll 0 0 #9FCC1D; } Additionally, I have defined another class that adds a background ...