CSS 覆盖内部 html 标签内的内容
我目前正在为论坛(diskusjon.no)制作自定义 CSS,但我一直在努力处理页面的某些部分。 IPBoard-forum 中的编辑器是原始 html-tag 内的 html-tag,我的 CSS 通过扩展名 Stylish< /a> 无法到达页面的这一部分。
结构是这样的:
<<html> <---lots of tags--> <iframe> <html> <body contenteditable=true>
现在我的样式影响除了第二个 html 标签之后的所有内容,所以我的问题是; - 当我通过 Stylish 添加 CSS 时,是否可以到达页面的这一部分。即我无权访问任何 HTML。
这是我正在讨论的部分的 Google Inspector 的图片:
I'm currently making a custom CSS for a forum (diskusjon.no), but I've been struggling with a certain part of the page. The editor in the IPBoard-forum is a html-tag inside the original html-tag, and my CSS set through the extension Stylish doesn't reach this part of the page.
The structure is something like this:
<<html> <---lots of tags--> <iframe> <html> <body contenteditable=true>
Now my style affects everything except what's after the second html-tag, so my question is; -is it possible to reach this part of the page at all when I'm adding my CSS through Stylish. i.e. I don't have access to any of the HTML.
Here's a picture of the Google Inspector for the part I'm talking about:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
由于
标记旨在加载外部页面,因此它将拥有自己的样式表。那么,你的风格就无法干扰它。
解决方案是在页面加载到 iframe 后使用 javascript。你可以参考这个:如何将CSS应用到iframe?问题。
Since the
<iframe>
tag is intended to load an external page, it will have it's own style-sheets. Then, your style cannot interfere with it.The solution is to use javascript after the page has been loaded into the iframe. You can refer to this: How to apply CSS to iframe? question.
无论页面是否在 iframe 中,Stylish 都会以相同的方式对待页面。因此,解决方案就是单独设置 iFramed 位的样式。
例如,假设您有页面 jsbin.com/osajuz/edit,并且它包含此 iFrame:
然后您可以创建一个时尚样式,例如:
效果很好。
如果您创建样式并访问 jsbin.com/osajuz,您会看到一些内容像这样:
同样,如果框架没有 URL,它将被视为来自同一域的页面,并且URL 作为包含页面。时尚规则仍然适用。
例如,如果您创建此时尚样式:
然后访问 jsbin.com/abazay/3/edit #preview,您将看到两种样式都应用于两个“内部”iFrame。
但请注意,如果您不小心,无论 JS 操作 iFrame 都可以覆盖 CSS 样式。因此,请自由使用
!important
标志来解决这个问题。Stylish treats a page the same whether it's in an iframe or not. So, the solution is just to style the iFramed bit separately.
For example, suppose you had the page jsbin.com/osajuz/edit, and it contained this iFrame:
Then you could create a Stylish style like:
which works.
If you create the style and visit jsbin.com/osajuz, you will see something like this:
Likewise, if the frame has no URL, it is treated as a page from the same domain and URL as the containing page. Stylish rules will still apply.
For example, if you create this Stylish style:
and then visit jsbin.com/abazay/3/edit#preview, you will see both styles applied to both "internal" iFrames.
But note that whatever JS is operating an iFrame can override CSS styles if you are not careful. Therefore make liberal use of the
!important
flag to combat this problem.