Is there any way to style a slot in a Vue component?
<slot style="position: absolute"></slot>
and
<slot class="slot"></slot>
do not work.
Wrap the slot in a <div>
and style the <div>
instead:
<div style="...">
<slot></slot>
</div>
If you really need to style the slot element, you can use CSS selectors like this:
<div class="wrapper">
<slot></slot>
</div>
.wrapper > * {
color: red;
}
I found such a way out.
computed: {
isAppBoxSlotActive() {
return Boolean(this.$slots['app-box']);
}
},
<div v-if="isAppBoxActive"
:class="$style['app-box']">
<slot name="app-box">...</slot>
</div>
You can pass a class from the parent like so:
In the component template:
<slot name="quoteText"></slot>
And when passing to the slot:
<p slot="quoteText" class="mb-md-100">Text</p>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With