Html 是否可以在 iframe 中只显示某个 div?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8287933/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 11:42:12  来源:igfitidea点击:

Is it possible to display only a certain div within an iframe?

csshtml

提问by Chris

Let's say i have an iframe with the page 2.htm set as the src.

假设我有一个页面 2.htm 设置为 src 的 iframe。

<iframe src="2.html"></iframe>

So this shows the 2.html. But 2.html has a div with the id 'within'. I want to only display the contents of 'within'.

所以这显示了2.html。但是 2.html 有一个带有 id 'within' 的 div。我只想显示“内”的内容。

How would i do this?

我该怎么做?

回答by Sameera Thilakasiri

This is the CSS and html code to accomplish the task:

这是完成任务的 CSS 和 html 代码:

<style>
#outerdiv
{
   width:446px;
   height:246px;
   overflow:hidden;
   position:relative;
}

#inneriframe
{
   position:absolute;
   top:-412px;
   left:-318px;
   width:1280px;
   height:1200px;
}
</style>
<div id="outerdiv">
    <iframe src="2.html" id="inneriframe" scrolling="no"></iframe>
</div>

Try this out: http://jsfiddle.net/57MRn/

试试这个:http: //jsfiddle.net/57MRn/

How does this work
The iframe is moved up within the outerdiv until only the within div is shown.


如何工作的 iframe 在外层 div 内向上移动,直到只显示内层 div。