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â.
Thanks for your time and support!
In the end the fix is so simple⌠putting the conditionals next to the colors
.badge-container .label-badge {
border-color: lime;
background-color: #1c1c1c;
}
changed to
.badge-container .label-badge {
border-color: {% if is_state('person.lainol','home') %} lime; {% else %} orange;
{% endif %};
background-color: #1c1c1c;
}
Thank you so much!!!
I would suggest to use another notation:
{% if ... %}
border-color: lime;
{% else %}
border-color: orange;
{% endif %}
More structural imho, also can be easily changed to
{% if ... %}
border-color: lime;
smth_else: bla-bla;
{% else %}
border-color: orange;
smth_else: bla-bla-bla;
{% endif %}
no to mention a possible indentation:
{% if ... %}
border-color: lime;
{% else %}
border-color: orange;
{% endif %}
Does anyone know a solution to the problem from this thread:
I have the same problem, but did not find a solution in this and the linked thread.
Installed card-mode via HACS.
My dashboard code:
- entity: person.christian
card_mod:
style: |
:host {
--label-badge-red: {% if is_state('person.christian', 'home') %} green {%else %} #db4537 {%endif %};
}
Be kind to describe the problem here.
I have this style added to the badge:
- entity: person.christian
card_mod:
style: |
:host {
--label-badge-red: {% if is_state('person.christian', 'home') %} green {%else %} #db4537 {%endif %};
}
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â.
Have now changed it:
- entity: person.christian
card_mod:
style: |
:host {
{% if is_state('person.christian', 'home') %} --label-badge-red: green {%else %} --label-badge-red: #db4537 {%endif %};
}
But the problem is still there.
Have now added this too.
Seems it is now working in the browser. After F5 it shows correct.
But sadly in the Android app I have still the same problem.
On open it does not show the correct colors.
Mmmm, have no Android. Try clearing a cache on a companion app.
You got any solution here? Finding the same problem and looking on how to decrease the todoist text.
type: custom:todoist-card
entity: sensor.to_do_list
show_completed: 0
show_header: true
use_quick_add: false
only_today_overdue: false
show_item_delete: false
card_mod:
style: |
ha-card {
color: black;
--ha-card-text-font-size: 50%;
}
Canât find the right convention to apply instead of text.
âha-card-text-font-size: 50%;
Can anyone help me out on what Im doing wrong here???
Im trying to show a different background image based on a sensor state
cards:
- type: custom:vertical-stack-in-card
style: |
ha-card {
{% if (states("sensor.temp_error_state").state == "Online" %}
border: solid 1px gray;
box-shadow: 5px 10px 10px rgba(0,0,0,.4);
background-image: url("/local/icons/cyan/online.png");
background-position: center;
background-size: cover;
background-repeat: no-repeat;
{% elif (states("sensor.temp_error_state").state == "Offline" %}
border: solid 1px red;
box-shadow: 5px 10px 10px rgba(200,0,1);
background-image: url("/local/icons/cyan/offline.png");
background-position: center;
background-size: cover;
background-repeat: no-repeat;
{% endif %}
}
Can you not cascade css styles this way???
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
Hopefully correcting these will get you there.
Im stupid⌠(as usual)
fixed it myself
cards:
- type: custom:vertical-stack-in-card
style: |
ha-card {
{% if states("sensor.temp_error_state") == "Online" %}
border: solid 1px gray;
box-shadow: 5px 10px 10px rgba(0,0,0,.4);
background-image: url("/local/icons/cyan/online.png");
background-position: center;
background-size: cover;
background-repeat: no-repeat;
{% elif states("sensor.temp_error_state") == "Offline" %}
border: solid 1px red;
box-shadow: 5px 10px 10px rgba(200,0,1);
background-image: url("/local/icons/cyan/offline.png");
background-position: center;
background-size: cover;
background-repeat: no-repeat;
{% endif %}
}
missing )) and no need for the .state
Hello, someone knows how I can delete the part of the title, itâs directly the name of the entity, but I canât hide it on the card
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:
type: picture-elements
image: /local/images/grid1280x1000.jpg
title: tide
elements:
- type: custom:canvas-gauge-card
entity: sensor.tide_high
gauge:
type: linear-gauge
width: 150px
height: 360px
colorPlate: '#ffffff00'
colorBar: '#fdf6ccff'
colorBarProgress: '#c2e1b7ff'
borderShadowWidth: 0
colorBorderOuter: black
colorBorderMiddle: '#ffffff00'
colorBorderInner: '#ffffff00'
colorBorderOuterEnd: '#ffffff00'
colorBorderMiddleEnd: '#ffffff00'
colorBorderInnerEnd: '#ffffff00'
majorTicks: none
strokeTicks: false
animate: false
barStrokeWidth: 0
barBeginCircle: false
valueBox: false
style:
left: 5%
bottom: 0%
transform: translate(0%,0%)
card_mod:
style: |
:host { height: 625px; }
- type: state-label
entity: sensor.t_avg
name: t avg
style:
left: 50%
card_mod:
style: |
@media (min-height: 700px) {
:host { top: 50%; color: red;}
@media (min-height: 800px) {
:host { top: 25%; color: blue;}
}
The last entity is there just to prove that card-mod is installed & working and capable of responding to @media statements.
Has anyone been able to extend their mobile background image up to the top of the phone where bat% and time is?
Here is my current setup and would like to extend the background up to the very top:
Iâve tried messing with the current code but wasnât able to achieve my goal.
card-mod-root: |
.header {
display: none;
}
#view {
padding: 0 !important;
height: 100vh !important;
}
Thanks for the help in advance
EDIT: Ive found this site that fix the problem but Iâm not sure how to implement it with card mod.