“Full screen” <iframe>

2019-01-03 12:27发布

When I use the following code to create an iframe:

<iframe src="mypage.html" style="border: 0; width: 100%; height: 100%">Your browser doesn't support iFrames.</iframe>

The iframe doesn't go all the way—a 10px white "border" surrounds the iframe. How could I solve this?

Here is an image of the problem:

Screenshot of site

标签: html iframe
8条回答
再贱就再见
2楼-- · 2019-01-03 12:35

The body has a default margin in most browsers. Try:

body {
    margin: 0;
}

in the page with the iframe.

查看更多
地球回转人心会变
3楼-- · 2019-01-03 12:46

Use frameborder="0". Here's a full example:

    <iframe src="mypage.htm" height="100%" width="100%" frameborder="0">Your browser doesnot support iframes<a href="myPageURL.htm"> click here to view the page directly. </a></iframe>
查看更多
看我几分像从前
4楼-- · 2019-01-03 12:46

Try adding the following attribute:

scrolling="no"
查看更多
可以哭但决不认输i
5楼-- · 2019-01-03 12:46

You could try frameborder=0.

查看更多
男人必须洒脱
6楼-- · 2019-01-03 12:47

You can also use viewport-percentage lengths to achieve this:

5.1.2. Viewport-percentage lengths: the ‘vw’, ‘vh’, ‘vmin’, ‘vmax’ units

The viewport-percentage lengths are relative to the size of the initial containing block. When the height or width of the initial containing block is changed, they are scaled accordingly.

Where 100vh represents the height of the viewport, and likewise 100vw represents the width.

Example Here

body {
    margin: 0;            /* Reset default margin */
}
iframe {
    display: block;       /* iframes are inline by default */
    background: #000;
    border: none;         /* Reset default border */
    height: 100vh;        /* Viewport-relative units */
    width: 100vw;
}
<iframe></iframe>

This is supported in most modern browsers - support can be found here.

查看更多
我欲成王,谁敢阻挡
7楼-- · 2019-01-03 12:50

Impossible to say without seeing a live example, but try giving both bodies margin: 0px

查看更多
登录 后发表回答