How do you put only a certain section of a website into an iframe?

后端 未结 3 546
自闭症患者
自闭症患者 2021-01-31 22:18

I\'m looking to put only a small part of a website into an iframe. How would I do this? Usually when I set up a iframe for a website (lets say yahoo) it gets the whole website..

3条回答
  •  清歌不尽
    2021-01-31 22:47

    In most of the cases the reference is external and you don’t have control over the external page. Thus you’ve to scroll the IFRAME content to the desired position. This of course is impossible. Yeah, there are some JavaScript hacks, but they’re all a bad solution, because the scrolling occurs only after the page is loaded. The Solution

    You can wrap the IFRAME into a div and scroll the DIV content using absolute TOP and LEFT CSS properties.

    Here’s an example:

    #my-div
    {
        width    : 400px;
        height   : 200px;
        overflow : hidden;
        position : relative;
    }
    
    #my-iframe
    {
        position : absolute;
        top      : -100px;
        left     : -100px;
        width    : 1280px;
        height   : 1200px;
    }
    

    Here you have one DIV with dimensions 400x200px. Now by moving the IFRAME within it you can position it on the right place.

提交回复
热议问题