在包含div的iframe中定位内容 [英] positioning content of an iframe within a containing div
问题描述
我有一个页面需要通过iframe进行投放,但是我只需要显示页面的一部分,而不是整个页面.
I've got a page which I need to serve via an iframe, but I need to only display part of the page, not the whole thing.
我当前的代码是:
<div style="display:block;overflow:hidden;width:500px;height:350px;">
<iframe height="350px" scrolling="no"
src="http://my/page/i/want/to/show/part/of/here/" width="500px"></iframe></div>
我认为最好的选择是在包含"overflow:hidden"的div内为iframe提供服务,使其像相框一样.那行得通,但是问题是我要显示的内容在iframe页面的中间,而div始终假定0,0是该帧的开始.我需要定位iframe,以便div恰好位于我要显示的页面部分上.
I thought that the best option would be to serve the iframe within a containing div that has "overflow:hidden" so that it acts like a picture frame. That works, but the problem is that the content I want to show is in the middle of the iframe page and the div is always assuming that 0,0 is the start of the frame. I need to position the iframe so that the div is exactly over the part of the page I want to be visible.
我可以这样做吗?
推荐答案
对margin-top和margin-left使用负值来定位iframe.看下面的代码:
Use negative values for margin-top and margin-left to position the iframe. Look at the code below:
<div style="display:block;overflow:hidden;width:500px;height:350px;">
<iframe style="margin-top:-100px;margin-left:-100px" height="350px" scrolling="no"
src="http://my/page/i/want/to/show/part/of/here/" width="500px"></iframe></div>
这篇关于在包含div的iframe中定位内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!