Search code examples
csshtmlweb-componentstylingcustom-element

How to style :root based on Custom Element Attribute


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

Is it not possible?

This Style rule is totally ignored


Solution

  • You forgot the parenthesis to :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>