如何设置样式:root基于自定义元素属性

问题描述 投票:1回答:1

Update: See: How to style :root without !important using proper specificity

这不可能吗?

此样式规则完全被忽略

css html5 web-component styling custom-element
1个回答
1
投票

你忘记了:host()的括号:

elem.attachShadow({mode: 'open'})
    .innerHTML = `
    <style>
      :host([player="X"]) { 
        display: inline-block;
        background: red;
        padding 1em; 
      }
    </style>
    Hello World`
<game-toes id=elem player="X"></game-toes>
© www.soinside.com 2019 - 2024. All rights reserved.