用聚合物影响(“渗出”)阴影DOM的外部CSS

编程入门 行业动态 更新时间:2024-10-26 22:17:19
本文介绍了用聚合物影响(“渗出”)阴影DOM的外部CSS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我必须缺少一些东西,但我不能弄清楚什么。我有简单的自定义元素实现与聚合物:

I must be missing something, but I can't figure it out what. I have simple custom element implemented with polymer:

<polymer-element name="test-elem"> <template> <content></content> <div id="container"> <div class="deepinside"> TECK ... CHEST </div> </div> </template> <script> Polymer('test-elem', { applyAuthorStyles: false, }); </script> </polymer-element>

然后在一个简单的页面中使用它:

I then use it in a simple page:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "www.w3/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="www.w3/1999/xhtml" lang="en"> <head> <meta http-equiv="Content-type" content="text/html;charset=UTF-8" /> <script src="libs/polymer.min.js"></script> <link rel="import" href="test-elem.html"> <style> .deepinside { color: red; } </style> </head> <body> <test-elem>Hi</test-elem> </body> </html>

元素的内部 div class =deepinside)显示为红色。如果我理解正确,这不应该发生(参见此文档)。注意,我在元素的构造函数中明确声明了 applyAuthorStyles:false (它不是必需的,因为它是默认行为)。我不明白为什么外部CSS影响的影子DOM中的元素。我甚至尝试在元素的定义中明确指定 shadowdom 属性,但结果是相同的。

The content of the element's inner div (with class="deepinside") is displayed in red. If I understand correctly, this shouldn't happen (see this doc). Note that I explicitly declared applyAuthorStyles: false in the element's constructor (it shouldn't be necessary, cause it is the default behavior). I don't understand why the external CSS is affecting an element in the shadow DOM. I've even tried specifying the shadowdom attribute explicitly in the element's definition, but the result is the same.

FWIW,我在OS X 10.7.5上运行Chrome版本31.0.1650.57。

FWIW, I'm running Chrome Version 31.0.1650.57 on OS X 10.7.5.

推荐答案

这是一个 Shadow DOM polyfill的已知限制。它在防止组件样式出血方面做得很好,但是它不会对其他方式做同样的事情。

This is an known limitation of the Shadow DOM polyfill. It does a pretty good job of preventing component styles from bleeding out, but it doesn't do the same for the other way around.

这里是一个用于你的用例的代码。它的工作原理是您打算在Chrome 33.0.1717.0 canary(其中Polymer不polyfill Shadow DOM),但不是在31.0.1650.57。

Here's a codepen for your use case. It works as you intend in Chrome 33.0.1717.0 canary (for which Polymer doesn't polyfill Shadow DOM), but not in 31.0.1650.57.

更多推荐

用聚合物影响(“渗出”)阴影DOM的外部CSS

本文发布于:2023-08-02 15:32:48,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1278925.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:聚合物   阴影   CSS   DOM

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!