CSS覆盖iframe中的内容的主体样式? [英] CSS override body style for content in iframe?

查看:737
本文介绍了CSS覆盖iframe中的内容的主体样式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何控制iframe中的body元素的背景图片和颜色?注意,嵌入的body元素有一个类,iframe是我的网站的一部分的页面。

How can I control the background image and colour of a body element within an iframe? Note, the embedded body element has a class, and the iframe is of page that is part of my site.

我需要这个的原因是我的网站有一个分配给正文的黑色背景,然后一个白色背景分配给包含文本的div。 WYSIWYG编辑器在编辑时使用iframe嵌入内容,但它不包括div,因此文本很难阅读。

The reason I need this is my site has a black background assigned to the body, and then a white background assigned to divs that contain text. A WYSIWYG editor uses an iframe to embed content when editing, but it doesn't include the div, so the text is very hard to read.

在编辑器中的iframe的主体有一个不在别的地方使用的类,所以Im假设这是放在那里,这样的问题可以解决。但是,当我将样式应用于class.body时,它们不会覆盖应用于body的样式。奇怪的是,样式确实出现在枞树,所以ive不知道发生了什么!

The body of the iframe when in the editor has a class that isn't used anywhere else, so Im assuming this was put there so problems like this could be solved. However when I apply styles to class.body they dont override the styles applied to body. The weird thing is that the styles do appear in firbug, so ive no idea whats going on!

感谢

UPDATE - Ive尝试@ mikeq的解决方案添加一个样式到类是body的类。这在添加到主页样式表时不起作用,但是当添加firebug时它会工作。 Im假设这是因为firebug应用于页面上的所有所有ements,因为css不应用于iframe中。这是否意味着添加CSS后的窗口加载与JavaScript将工作?

UPDATE - Ive tried @mikeq's solution of adding a style to the class that is the body's class. This doesn't work when added to the main page stylesheet, but it does work when added with firebug. Im assuming this is because firebug is applied to all all ements on the page where as the css is not applied within iframes. Does this mean that adding the css after window load with javascript would work?

推荐答案

iframe是您的网页中的洞,显示其中的另一个网页。

An iframe is a 'hole' in your page that displays another web page inside of it. The contents of the iframe is not in any shape or form part of your parent page.

如其他人所说,您的选项是:

As others have stated, your options are:


  • 给正在iframe中加载的文件

  • <
  • 不使用iframe(您确定需要一个iframe吗?)

这篇关于CSS覆盖iframe中的内容的主体样式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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