How can I scale the content of an iframe?

前端 未结 17 2090
后悔当初
后悔当初 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:33

    This was my solution on a page with 890px width

    #frame { 
    overflow: hidden;
    position: relative;
    width:1044px;
    height:1600px;
    -ms-zoom: 0.85;
    -moz-transform: scale(0.85);
    -moz-transform-origin: 0px 0;
    -o-transform: scale(0.85);
    -o-transform-origin: 0 0;
    -webkit-transform: scale(0.85);
    -webkit-transform-origin: 0 0; 
    
    }
    
    0 讨论(0)
  • 2020-11-22 12:34

    Followup to lxs's answer: I noticed a problem where having both the zoom and --webkit-transform tags at the same time seems to confound Chrome (version 15.0.874.15) by doing a double-zoom sort of effect. I was able to work around the issue by replacing zoom with -ms-zoom (targeted only at IE), leaving Chrome to make use of just the --webkit-transform tag, and that cleared things up.

    0 讨论(0)
  • 2020-11-22 12:37

    I just tested and for me, none of the other solutions worked. I simply tried this and it worked perfectly on Firefox and Chrome, just as I had expected:

    <div class='wrap'>
        <iframe ...></iframe>
    </div>
    

    and the css:

    .wrap {
        width: 640px;
        height: 480px;
        overflow: hidden;
    }
    
    iframe {
        width: 76.92% !important;
        height: 76.92% !important;
        -webkit-transform: scale(1.3);
        transform: scale(1.3);
        -webkit-transform-origin: 0 0;
        transform-origin: 0 0;
    }
    

    This scales all the content by 30%. The width/height percentages of course need to be adjusted accordingly (1/scale_factor).

    0 讨论(0)
  • 2020-11-22 12:38

    I found a solution that works in IE and Firefox (at least on the current versions). On Safari/Chrome, the iframe is resized to 75% of its original size, but the content within the iframe is not scaled at all. In Opera, this doesn't seem to work. This feels a bit esoteric, so if there is a better way to do it I'd welcome suggestions.

    <style>
    #wrap { width: 600px; height: 390px; padding: 0; overflow: hidden; }
    #frame { width: 800px; height: 520px; border: 1px solid black; }
    #frame { zoom: 0.75; -moz-transform: scale(0.75); -moz-transform-origin: 0 0; }
    </style>
    
    ...
    
    <p>Some text before the frame</p>
    <div id="wrap">
    <iframe id="frame" src="test2.html"></iframe>
    </div>
    <p>Some text after the frame</p>
    </body>
    

    Note: I had to use the wrap element for Firefox. For some reason, in Firefox when you scale the object down by 75%, it still uses the original size of the image for layout reasons. (Try removing the div from the sample code above and you'll see what I mean.)

    I found some of this from this question.

    0 讨论(0)
  • 2020-11-22 12:40

    Thought I'd share what I came up with, using much of what was given above. I haven't checked Chrome, but it works in IE, Firefox and Safari, so far as I can tell.

    The specifics offsets and zoom factor in this example worked for shrinking and centering two websites in iframes for Facebook tabs (810px width).

    The two sites used were a wordpress site and a ning network. I'm not very good with html, so this could probably have been done better, but the result seems good.

    <style>
        #wrap { width: 1620px; height: 3500px; padding: 0; position:relative; left:-100px; top:0px; overflow: hidden; }
        #frame { width: 1620px; height: 3500px; position:relative; left:-65px; top:0px; }
        #frame { -ms-zoom: 0.7; -moz-transform: scale(0.7); -moz-transform-origin: 0px 0; -o-transform: scale(0.7); -o-transform-origin: 0 0; -webkit-transform: scale(0.7); -webkit-transform-origin: 0 0; }
    </style>
    <div id="wrap">
        <iframe id="frame" src="http://www.example.com"></iframe>
    </div>
    
    0 讨论(0)
提交回复
热议问题