Skip to content

Instantly share code, notes, and snippets.

@smpnjn
Created May 5, 2021 12:22
Show Gist options
  • Save smpnjn/a3b214aefc42e1125d3976f0c6340165 to your computer and use it in GitHub Desktop.
Save smpnjn/a3b214aefc42e1125d3976f0c6340165 to your computer and use it in GitHub Desktop.
class Paragraph extends HTMLElement {
constructor() {
super()
// Attach shadow DOM
let shadow = this.attachShadow({mode: 'open'});
// Append our Paragraph
shadow.innerHTML = '<p>Hello</p>'
// Add in our CSS
let style = document.createElement('style');
let elCss = style.textContent = `
p {
color: red;
font-size: 1.25rem;
}
`;
// Append our CSS
shadow.appendChild(style);
}
}
customElements.define('alpha-paragraph', Paragraph);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment