'How to apply multi classes to an element/ combine conditional static classes
I want to apply multiple css classes to one element. How do I do it? One conditional and one static.
<p
class={current === 'overview' ? 'selected' : '' // here I want to add another class named foo}
on:click={() => (current = 'overview')}
>
Solution 1:[1]
To make life easier you can use the class: directive
<p class="foo" class:selected={current === 'overview'}>
Solution 2:[2]
Separate by whitespace according to HTML standard class="{current === 'overview' ? 'selected' : ''} foo"
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Stephane Vanraes |
| Solution 2 |
