[英]Is it somehow possible to style an iframes before/after pseudo-element?
As the title says, is there a way to style an iframes pseudo before
/ after
? 正如标题所说,有没有办法在
before
/ after
iframes伪样式? Without wrapping the iframe with another div
, or else?` 没有用另一个
div
包装iframe,或者?`
I tried to style it like any other element, but no success: 我试着像任何其他元素一样设计样式,但没有成功:
iframe::before {
content: 'foo';
position: absolute;
top: 0;
left: 0;
}
iframe::after {
content: 'bar';
position: absolute;
top: 0;
right: 0;
}
http://fiddle.jshell.net/ppRqm/ http://fiddle.jshell.net/ppRqm/
Update 更新
A known workaround is to add the before/after to an element in the source file: http://fiddle.jshell.net/ppRqm/2/ 一个已知的解决方法是将前/后添加到源文件中的元素: http : //fiddle.jshell.net/ppRqm/2/
But sometimes you've no access to the source-file. 但有时您无法访问源文件。
I am not sure but I think it isn't possible. 我不确定,但我认为这是不可能的。 Or the logic behind an iframe makes it imposible to achieve.
或者iframe背后的逻辑使其无法实现。
As you know, pseudo-elements are added to its container , if you do that with an iframe, pseudo-elements would be added inside the iframe. 如您所知,伪元素被添加到其容器中 ,如果您使用iframe执行此操作,则会在iframe中添加伪元素。 But, and here's the problem, the iframe content, the inline content , will just load if the browser doesn't support iframes.
但是,这就是问题,如果浏览器不支持iframe,那么iframe内容就会加载内联内容 。
This means that this: 这意味着:
<iframe>
<div>Your browser doesn't support iframes</div>
</iframe>
And adding pseudo-elements, will do the same thing; 并且添加伪元素,会做同样的事情; on modern browsers inline content wouldn't be displayed .
在现代浏览器上, 内联内容 不会显示 。
Direct Work-Around for Debugging Purposes 直接解决调试目的
I have a debugging CSS tier that gives an outline
to elements with invalid or obsolete code. 我有一个调试CSS层,它给出了带有无效或过时代码的元素的
outline
。 While not exactly an answer someone may find it helpful as I was trying to find a way to visually ensure that any content embedded with an iframe had an allowfullscreen="true"
attribute/value. 虽然不完全是一个答案,有人可能会发现它有用,因为我试图找到一种方法来直观地确保嵌入iframe的任何内容都有
allowfullscreen="true"
属性/值。 This work-around uses a sibling selector and it works well-enough. 这种解决方法使用兄弟选择器,它运行良好。
iframe:not([allowfullscreen]) + *::after
{
background-color: #f00;
border: #f00 solid 4px;
color: #fff;
content: 'Missing allowfullscreen attribute on iframe!' !important;
font-size: 24px;
padding: 4px;
}
Direct Styling using Third Element 使用第三元素直接造型
If you're looking to position relative to the iframe my next recommendation would be to set the iframe's parent position to position: relative;
如果您要查找相对于iframe的位置,我的下一个建议是将iframe的父位置设置为
position: relative;
and then set position: absolute;
然后设置
position: absolute;
on a third element to match the iframe's rendering. 在第三个元素上匹配iframe的渲染。 Lastly you could finally apply the
::after
on that third element. 最后,您最终可以在第三个元素上应用
::after
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.