Skip to content

Instantly share code, notes, and snippets.

@heyMP
Created April 17, 2025 14:37
Show Gist options
  • Save heyMP/c57834b2bcf56425a3d93f74a91aad6e to your computer and use it in GitHub Desktop.
Save heyMP/c57834b2bcf56425a3d93f74a91aad6e to your computer and use it in GitHub Desktop.
Inject Styles into Lit component with Constructible Stylesheets
// before we add our component to the DOM
// we are going to alter the rh-cta definition
// this will alter the stylesheet for all CTAs
await customElements.whenDefined('rh-cta').then(() => {
const RhCta = customElements.get('rh-cta');
if (!RhCta) { return; }
const styles = RhCta.styles?.[0].styleSheet as CSSStyleSheet;
styles.insertRule(`
::slotted(a) { white-space: normal !important; }
`, styles.cssRules.length);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment