I'm currently trying to change the background color of a label based on a value. At the same time, I would like to change the color of the label if the user clicks it or hovers over it. Currently, I have the click and hover done (using separate CSS classes), but I'm unsure of how to make the value portion work as well.
I have a simple boolean value (called 'displayValueTrueClass') set to true in a TypeScript file. If that value is true, then I want to change the CSS class to a 'valueTrue' class.
Here is my HTML:
<section class="ac-container">
<div>
<input id="id-1" name="id-1" type="checkbox" />
<label [ngClass]="{'valueTrue': displayValueTrueClass}" for="id-1">Panel Name Goes Here</label>
</div>
and here is my CSS:
.ac-container {
width: 100%;
margin: 10px auto 30px auto;
}
.valueTrue {
background-color: #060bf7;
color: #ffffff;
}
.ac-container label {
padding: 4px 20px;
position: relative;
display: block;
height: 25px;
cursor: pointer;
color: #ffffff;
font-size: 12px;
background: #404040;
}
.ac-container label:hover {
background-color: #000000;
}
.ac-container input:checked + label,
.ac-container input:checked + label:hover{
background-color: #4ed017;
color: #ffffff;
}
.ac-container label-broken {
background-color: #ff0000;
color: #ffffff;
}
My typescript has the boolean set to true:
displayValueTrueClass: boolean = true;
I can confirm that the ngClass line does display using the appropriate CSS class, but only if I remove all of the other .ac-container:label classes, so it seems like those are maybe taking precedence over the valueTrue
class?
I'm fairly new to constructing HTML with CSS. I'm pretty sure I'm using 'ngClass' correctly so I'm unsure why the appropriate class isn't applied when that value is true.