How can I scale the content of an iframe?

前端 未结 17 2356
后悔当初
后悔当初 2020-11-22 11:46

How can I scale the content of an iframe (in my example it is an HTML page, and is not a popup) in a page of my web site?

For example, I want to display the content

17条回答
  •  感动是毒
    2020-11-22 12:32

    You don't need to wrap the iframe with an additional tag. Just make sure you increase the width and height of the iframe by the same amount you scale down the iframe.

    e.g. to scale the iframe content to 80% :

    #frame { /* Example size! */
        height: 400px; /* original height */
        width: 100%; /* original width */
    }
    #frame {
        height: 500px; /* new height (400 * (1/0.8) ) */
        width: 125%; /* new width (100 * (1/0.8) )*/
    
        transform: scale(0.8); 
        transform-origin: 0 0;
    }
    

    Basically, to get the same size iframe you need to scale the dimensions.

提交回复
热议问题