Change icon coulour and text based on value
Posted: Saturday 22 January 2022 17:44
Hi,
I created adevice which shows we the air quality index (LKI), which varies from 1 to 11.
Depending on the value I want the icon and text to change colour. I added the following in custom.js:
In the custom.css I added:
This works great, but I don't want only the icon to change, but also the colour of the text on the button when level medium of higher. CSS is not my strongest point, please point me into the right direction.
Jeroen
I created adevice which shows we the air quality index (LKI), which varies from 1 to 11.
Depending on the value I want the icon and text to change colour. I added the following in custom.js:
Code: Select all
function getStatus_Luchtkwaliteit(block) {
var device=block.device;
if(device['Data']<4) {
block.addClass='alertnormal';
}
else if (device['Data']<6) {
block.addClass='alertlight';
}
else if (device['Data']<8) {
block.addClass='alertmedium';
}
else if (device['Data']<10) {
block.addClass='alerthigh';
}
else {
block.addClass='alertcritical';
}
}
Code: Select all
.alertnormal .col-icon {
color: green !important;
}
.alertlight .col-icon {
color: yellow !important;
}
.alertmedium .col-icon {
color: orange !important;
}
.alerthigh .col-icon {
color: orangered !important;
}
.alertcritical .col-icon {
color: red !important;
}
Jeroen