Condition in CSS style (text node)

Hi,
I found in forum this code to set background color of a text node

<style>
[node-id="9a6b2f8.2010d5"] {
    background-color: red !important;
}
</style>

Can I insert a condition to have the background-color = red only if the text is ON or a global variable is ON (better)?

It somewhat depends on the browser. But in general, yes, you can do that. However, in your example, you are missing a leading # or . - presumable a # as it looks like an ID. Of course, you will have to use the dev tools in your browser to find a suitable selector.

With Dashboard v3 you can use msg.className to set a custom class for the node.

So you need a template node with a little CSS

<style>
md-card.nr-dashboard-text.on {
    background-color: red;
}
md-card.nr-dashboard-text.off {
    background-color: slategrey;
}
</style>

Then when you send some text to the node, also set msg.className to "on" or "off".
You can do that based on the contents of msg.payload or a context variable as you wish, using a Function or Change node.

1 Like

I just tried and it's works fine.
Thank you .....

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.