Hi all, Iâm trying to stylize the person badgesâŚ
I want to colorize the badges depending on state (home, away, etc) like example 1 (left one), with the badge container border in color (lime = home, orange = away, etc), but the best I can do is like example 2 (right one), gray container border, only the circular border with color. Donât know how integrate âha-label-badge:â into the âifâ states.
Here is my code of example 1 and 2 , any help is appreciated. Thx!
Why do you put it here?
It is misplaced.
Use examples from â1st post â link at the bottom â badgesâ as a starting point.
When you build a proper DOM path - then you will see how to âintegrate âha-label-badge:â into the âifâ statesâ.
Because I donât really know how it works, itâs a hit&miss procedure until it works . Too complicated for my brainâŚ
My problem is that I canât change badge-container color, border and background as easy as the --label-badge⌠in the different states provided by :host {%ifâŚ
Itâs OK, the âhit&missâ procedure exactly what is used by lots of people (including me who never dealt with CSS before card-mod).
The link I gave you earlier explains that there are 2 ways of styling some element:
By defining CSS properties for some PARTICULAR element (âdirect access wayâ) - and you need to specify a PATH to this element.
By defining special variables like ââlabel-badge-text-colorâ (âvariable wayâ) for the whole badge (which can be addressed as â:hostâ). In a code of HA some properties of some elements are defined based on similar variables, and a user do not have to know a path to some element, he only need to define a corr. variable on a particular badge level or globally in a custom theme.
This is applicable for many UI parts, not to badges only. And to style some UI part sometimes a combination of both ways is used.
In the link given earlier both ways (âdirectâ, âvariableâ) are illustrated by examples.
Your 1st code is based on a provided âdirect wayâ example.
Your 2nd code (but with errors) is based on a âcombinedâ example.
Your task may be split:
Provide STATIC (w/o âifâ) styles for elements.
Then - make some of these styles dynamic.
So, first prepare a STATIC styling.
Use the 1st code as a starting point (it seems to be correct).
Suggestion: use different colors to be sure that is styled properly, not like âlime for several elementsâ.
It shows correct in the browser on my PC after coming from âRaw editâ screen and if I hit refresh (F5) the page reloads and I donât see the changed color.
On my Android phone I donât see the changed color if I open the app.
Only sometimes after a refresh the colors are working.
May be not related, but if the condition is false then your code is
some_path {
some_property:
}
which causes an error. In most cases this is not critical, but this is not âsolidâ.
See a few posts above HOW to properly wrap styles in âif elseâ code.
Also, have you read this in part of âextra_module_urlâ.
Try putting your code into Developer Tools > Template. It should highlight a couple of code errors:
{% if (states("sensor.temp_error_state").state == "Online" %}
youâve opened a bracket pair without closing it
states("sensor.temp_error_state") is all you need to return the sensor state. Adding .state means you are looking for an attribute of the state called state, which is obviously meaningless. This would only be needed if you were using the more long-winded square brackets notation i.e. states["sensor.temp_error_state"].state
Have a look in the dom on the right side. It is inside shadow root and not directly in ha-card. So you have to go one level deeper. Search for card-header in this thread. Asked and answered a lot of times.
Does custom:canvas-gauge-card belong to the list of cards that canât be modified with card-mod? Iâm using it within a picture_elements card so I can see <ha-card class="type-picture-elements"> when I inspect the card, but not within this for the gauge itself. The line before </canvas-gauge-card> is <card-mod slot='none'> and I am able to get things inserted into this section but they have no effect on the card size (Iâm trying to adjust its height in response to the pc or phoneâs screen size, either by explicitly re-stating the gaugeâs size or by scaling it).
My experimental card (much simplified) yaml: