Html 如何将 css 样式应用到 iframe 内容中?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15812946/
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
How to applying css style into an iframe content?
提问by Vineesh Trivandrum
I am trying to apply a CSS style for content inside the iframe, please check this link http://jsfiddle.net/pPqGe/
我正在尝试为 iframe 内的内容应用 CSS 样式,请查看此链接http://jsfiddle.net/pPqGe/
jQuery:
jQuery:
$(document).ready(function() {
$('iframe').contents().find('h1').css('color','red');
});
HTML:
HTML:
<iframe src="mysite" width="100%" height="100%" id="myframe"></iframe>
For iframe source I have used a live website.
对于 iframe 源,我使用了一个实时网站。
回答by Christoffer Helgelin Hald
It works. Problem is there is no H1, only H2. Check out this link http://jsfiddle.net/pPqGe/1545/.
有用。问题是没有H1,只有H2。查看此链接http://jsfiddle.net/pPqGe/1545/。
HTML:
HTML:
<iframe src='jsfiddle.net'></iframe>
JavaScript:
JavaScript:
$(document).ready(function() {
$('iframe').contents().find('h2').css('color','red');
$('iframe').contents().find('#header').css('opacity','.2');
});