Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width,initial-scale=1" />
    <title>Part overrides inline style</title>
    <style>
      test-element::part(swatch) {
        background-color: red;
      }
    </style>
    <script>
      class TestElement extends HTMLElement {
        constructor() {
          super();
          this.attachShadow({ mode: "open" }).innerHTML = `
          <div part="swatch"
            style="background-color: green; height: 100px; width: 100px;"
          ></div>
        `;
        }
      }
      customElements.define("test-element", TestElement);
    </script>
  </head>
  <body>
    <p>
      Is this box green or red?
    </p>
    <test-element id="test"></test-element>
  </body>
</html>
Output 300px

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
JanMiksovskypro
0viewers