Home  >  Q&A  >  body text

"The :deep() selector in Vue3 is invalid when using the PrimeVue library"

<p>I am using vue3 and PrimeVue library. When I try to override the PrimeView component's css field using the <code>:deep()</code> selector, it has no effect. It only applies my changes when I use unscoped styles. I'm confused as to why it doesn't work. </p> <p>Sample code with <code>:deep()</code>: </p> <pre class="brush:js;toolbar:false;"><template> <Toast position='buttom-right'/> </template> <style scoped> :deep(.p-toast-message-icon) { margin-right: 10px !important; } </style> </pre> <p>This doesn't work. </p> <p>But when using <code>style</code> without scope, like this: </p> <pre class="brush:js;toolbar:false;"><style> .p-toast-message-icon { margin-right: 10px !important; } </style> </pre> <p>That works. </p>
P粉785522400P粉785522400416 days ago545

reply all(1)I'll reply

  • P粉094351878

    P粉0943518782023-08-30 16:40:49

    The rules generated through the :deep selector will take effect for the child elements of the current component, but p-toast is attached to the element, so the generated class will have no effect.

    However, you can set pass options to pass style rules to the icon:

    <Toast
        :pt="{
            icon: { style: 'marginRight: 10px !important;' }
        }"
    />
    

    or

    <Toast
        :pt="{
            icon: { class: 'mr-2' }
        }"
    />
    

    See examples in Sandbox.

    reply
    0
  • Cancelreply