0

very simple but stuck. I used conditional CSS in a js file

get  styleClass(){
 return this.show ? 'class0': 'class1';
    }

In the HTML file, the div class looks like

<div class="slds-box slds-p-left_xxx-small slds-theme_default card"> Now how can i put {styleClass} in div class like
<div class="slds-box slds-p-left_xxx-small slds-theme_default card {styleClass}"> but its not working.What is the best way?

0

1 Answer 1

1

Such conditional CSS is not supported by LWC, you need to include all the CSS in a class property:

<div class={styleClass}>
get styleClass(){
    return `slds-box slds-p-left_xxx-small slds-theme_default card ${this.show ? 'class0': 'class1'}`;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.