Inactive link" /> Inactive link" /> Inactive link"/>

How to apply unocss rule when element has certain modifier class?

318 Views Asked by At

I have a HTML page where links sometimes have router-link-active class added by a third party library:

<a href=".." class="text-red">Inactive link</a>
<a href=".." class="text-red router-link-active">Active link</a>

I want to style the links with unocss so that active links are blue instead of red. How do I do that? The proposed code would supposedly look like:

<a href=".." class="text-red has-(.router-link-active):text-blue">Link</a>

generating the following CSS:

has-\(\.router-link-active\)\:text-blue.router-link-active {
  color: blue;
}
2

There are 2 best solutions below

0
Ilya Semenov On

Sorry for the fuzz, I figured this:

<a href=".." class="text-red [&.router-link-active]:text-blue">Link</a>
0
exside On

Or you could simply configure a shortcut in your config targeting the "external" class:

...,
shortcuts: [
    { 'router-link-active': 'text-blue' },
    ...
],
...