This code will help you to understand how to conditionally change the CSS class names for a Blazor element.
You have to use the binding in a ternary operator to achieve this.
<div class="menu @(IsOpen ? "open" : "")"></div> <button @onclick="@AddClass">Add Class</button> @code { private bool IsOpen { get; set; } = false; private void AddClass() { IsOpen = !IsOpen; } }
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
You have to use the binding in a ternary operator to achieve this.
need an explanation for this answer? contact us directly to get an explanation for this answer