iframe 中的绝对位置元素? [英] Absolute position elements within iframe?

查看:81
本文介绍了iframe 中的绝对位置元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想相对于文档绝对定位 iframe 中的元素.我正在使用这个

I want to absolute position an element in iframe relative to the document. I'm using this

.myClass
{
    position: absolute;
    top: 0;
    left: 0;
}

但它不会将元素定位在文档的左上角,而是定位在 iframe 的左上角.如何将其定位到文档?jquery/javascript 解决方案是可以接受的

but it do not position the element at top left of document, it's positioned at top left of the iframe. How to apsolute position it to the document? jquery/javascript solutions are acceptable

推荐答案

var iframe = top.frames[name].document;
var css = '' +
           '<style type="text/css">' +
           'body{margin:0;padding:0;postiton:absolute}' +
           '</style>';
iframe.open();
iframe.write(css);
iframe.close();

您必须在 HTML 中而不是在 css 文件中执行此操作.但是iframe中对象的内部样式必须在页面加载的网站/服务器的css中处理

You have to do that in HTML not in the css file. But the inner style of the object in the iframe must be handled in the css of the website/server from where the page loads

这篇关于iframe 中的绝对位置元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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