【发布时间】:2018-07-18 06:58:48
【问题描述】:
我正在尝试编写一些 web 组件来响应它们所在容器的主题。即
<div dataset-theme='light'>
<my-custom-element></my-custom-element>
</div>
<div dataset-theme='dark'>
<my-custom-element></my-custom-element>
</div>
我想将深色主题中的背景颜色更改为深色。我在 shadow-root 中尝试了如下 CSS:
[dataset-theme='dark']
:host
background-color: #333
但它似乎根本没有回应。有没有办法让 web 组件的样式根据它所在的容器而改变?
【问题讨论】:
-
你试过
[dataset-theme='dark'] my-custom-element{background-color: #333}吗?
标签: css html web-component shadow-dom custom-element