How to apply css to iframe content? [closed]

2019-01-07 15:37发布

I am unable to get CSS generated content to work for iframe elements:

iframe::after {content: 'example';}
iframe::before {content: 'example';}

Does anyone have a solution that actually works? Thanks in advance.

标签: css iframe
2条回答
啃猪蹄的小仙女
2楼-- · 2019-01-07 15:59

Is the iframe dynamically created, or is it something that is mostly static (light a iframe used for lightbox effect).

If it is static, you can simply use style tags inside the iframe markup, or better yet include an external stylesheet by linking to it in the iframe markup.

If it is dynamic, you are best off using the jQuery JavaScript library as it is exceptionally good for handling CSS.

查看更多
我想做一个坏孩纸
3楼-- · 2019-01-07 16:01

You can use jQuery's .content() function to access it.

$('yourIframe').contents().find('#yourItemYouWantToChange').css({
    opacity: 0,
    color: 'purple'
});

Example

Here's an example showing me applying css to the jQuery logo typically found in the top left of the screen. Mind you, it has to be same domain/ports etc, so that's why my example features jsfiddle in the iframe.
http://jsfiddle.net/pPqGe/

查看更多
登录 后发表回答