#Component slot not being styled
1 messages · Page 1 of 1 (latest)
Hi @desert patio. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
Yes, you can use the :global() selector in your component's local style to apply CSS styles to the child elements that are passed through the <slot/>. This allows you to style elements with a specific class within the slotted content.
Here's an example from the Astro documentation (https://docs.astro.build/en/guides/styling#global-styles):
<style>
/* Scoped to this component, only. */
h1 { color: red; }
/* Mixed: Applies to child `h1` elements only. */
article :global(h1) {
color: blue;
}
</style>
<h1>Title</h1>
<article><slot /></article>
In this example, the :global(h1) selector is used to apply styles to child h1 elements within the <slot/>. You can adapt this pattern to style the class you're targeting within the slotted content.