add web component styles exercise
Neue Datei |
| | |
| | | <!DOCTYPE html>
|
| | | <html lang="en">
|
| | | <head>
|
| | | <meta charset="UTF-8">
|
| | | <title>Web Component Styles</title>
|
| | | <script defer src="web-component-styles.js"></script>
|
| | | </head>
|
| | | <body>
|
| | | <style>
|
| | | /* Outer Styles */
|
| | | </style>
|
| | | <my-component></my-component>
|
| | | <div class="inner">Global Text with inner class</div>
|
| | | <div class="outer">Global Text with outer class</div>
|
| | | </body>
|
| | | </html>
|
Neue Datei |
| | |
| | | class MyComponent extends HTMLElement {
|
| | | constructor() {
|
| | | super();
|
| | |
|
| | | const shadowRoot = this.attachShadow({mode: "open"});
|
| | |
|
| | | shadowRoot.innerHTML = `
|
| | | <style>
|
| | | :host {
|
| | | display: block;
|
| | | }
|
| | | |
| | | .inner {
|
| | | /* Inner Styles */
|
| | | }
|
| | | </style>
|
| | | |
| | | <div class="inner">Web Component Text with inner class</div>
|
| | | <div class="outer">Web Component Text with outer class</div> |
| | | `;
|
| | | }
|
| | | }
|
| | |
|
| | | window.customElements.define("my-component", MyComponent);
|