是否可以在iframe中只显示某个div? [英] Is it possible to display only a certain div within an iframe?

查看:499
本文介绍了是否可以在iframe中只显示某个div?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

这里显示了2.html。但是2.html有一个div,id'在'内。

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'.

推荐答案

我想要只显示内部的内容。方案

解决方案

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

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

<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>

尝试此操作: http://jsfiddle.net/57MRn/

工作原理

iframe在outerdiv中向上移动,直到只显示within div。

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

这篇关于是否可以在iframe中只显示某个div?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆