To customize a CSS class from a UI library in Vue, like the n-dropdown
component from Naive UI, and specifically modify the deeply nested
n-dropdown-option-body__prefix--show-icon
class within the current component using CSS modules, you can utilize the
:global
keyword. Here's how you can achieve this:
<template>
<n-dropdown :class="$style.menu">
</n-dropdown>
</template>
<style module>
.menu:global.n-dropdown-menu .n-dropdown-option .n-dropdown-option-body .n-dropdown-option-body__prefix.n-dropdown-option-body__prefix--show-icon {
margin-left: 33px;
margin-right: 19px;
}
</style>
This will result in a selector that looks like:
.MobileNavMenu_menu_NhSka.n-dropdown-menu .n-dropdown-option .n-dropdown-option-body .n-dropdown-option-body__prefix.n-dropdown-option-body__prefix--show-icon {
margin-left: 33px;
margin-right: 19px;
}
Any classes specified after the :global
keyword will remain unaffected by module manipulations.
If the .n-dropdown-menu
should be a child of the menu
, ensure to add whitespace around the :global
declaration:
.menu :global .n-dropdown-menu
Failure to do so may lead to unexpected crashes in Vue.