I have multiple css classes that make up a button using SCSS.
.ghost-button {
// CSS goes here
}
.ghost-button-label {
// CSS goes here
}
.plus-circle {
//CSS goes here
}
Using Angular I can control the disabled state using the following feature.
[class.disabled]="booleanFlag"
I wanted to have a disabled state for this button with out having multiple disabled classes like so,
.ghost-button.disabled {
// CSS goes here
}
.ghost-button-label.disabled {
// CSS goes here
}
.plus-circle.disabled {
//CSS goes here
}
This is an example of what I am trying to do. This did not work for me.
.ghost-button .ghost-button-label .plus-circle-position .disabled {
//CSS goes here
}
Here is the markup I use for the button,
<div style="padding-top: 10px" (click)="handleClickAdd($event)">
<div class="ghost-button ghost-button-label icon-custom icon-margin plus-circle plus-circle-position" [class.disabled]="blockAdditions">
<div>
<div>Add</div>
</div>
</div>
</div>
Is there a way to do this? Thanks.
This doesn't work because it means each class is a descendant of the previous:
If you're trying to just select that one div with all four classes, just remove the spaces:
If you're trying to select any elements that have the disabled class plus one of the three other classes, then you use commas to separate the different combinations:
Of course you could just select
.disabledif you want this CSS applied to every element with the disabled class:Just be sure to take into account View Encapsulation. You may need to put this CSS in the global style file
styles.cssif this class exists in more than one component.Just a note, you are not setting the
disabledstate here, you are adding a class with the name "disabled".disabledis a boolean attribute you can set via HTML, which you can then select with the pseudo-class:disabled.If this is what you were actually trying to do then in Angular it would be: