Reputation: 3365
I need to add a class to the parent <li>
tag of a NavLink when the NavLink is active, however I struggle to find out how to do so especially since there exists no CSS selector to select parent elements, and apparently NavLink does not expose any IsActive
property. My code is:
<li>
<NavLink href="@Url">
@Text
</NavLink>
</li>
And my css
li.some-class-needing-to-be-set < a.active {
property: value;
}
Upvotes: 1
Views: 1198
Reputation: 933
I tried in my side to try an easy solution but indeed it seems that NavLink does not have an easy way to get if it is Active or not.
I found this code example: https://www.codegrepper.com/code-examples/whatever/navbar+change+active+class+link+blazor
I think it could be the good solution for you, with some small modifications. If you need any help to do so, do not hesitate, I'll be glad to try to help you.
Upvotes: 2