轻型DOM样式级联到阴影DOM [英] Light DOM style cascades down to the shadow DOM

查看:62
本文介绍了轻型DOM样式级联到阴影DOM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用聚合物创建了一个自定义元素.当元素包含在h2中时,它将继承h2boldnessfont-size.我需要使我的组件避开外界,并且不受光影风格的影响.如果轻型DOM级联下来,如何实现?

I have created a custom element with polymer. When the element is included within an h2, it inherits the h2's boldness and font-size. I need my components to be sheltered from the outside world and not be affected by light dom styles. How can I achieve this if the light DOM cascades down?

更具体地说,请查看以下内容:

To be more specific, check out the following:

推荐答案

这似乎是经设计:

影子树的顶级元素从其宿主元素继承.

The top-level elements of a shadow tree inherit from their host element.

在这种情况下,主机元素是h2.

The host element in this case is the h2.

您需要在自定义元素的CSS中包含明确的大小和权重声明,以防止其从其宿主元素继承样式.

You will need to include explicit size and weight declarations in your custom element's CSS in order to prevent it from inheriting the styles from its host element.

这篇关于轻型DOM样式级联到阴影DOM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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