Q:

How do I conditionally change the CSS class names for a Blazor element?

0

This code will help you to understand how to conditionally change the CSS class names for a Blazor element.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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;
    }
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now