šŸ”¹ Card-mod - Add css styles to any lovelace card

Already suggested that above. But it seems Christoph want to stay with only setting the variables. :wink:

Thanks both for the adviceā€¦ :slight_smile:
first, I want to try it this way - Probably, I will either change it to the Styles or - remove it completely, when I donā€™t like it at all.

I am aware of the current situation and that the variables can - and might change at any time.
Right now, it is more to create somehow a ā€œprototypeā€ of a dashboard design - triggered with the recent updates and new color options at all.

Yes, but if you go the other way, you are not correlated to any of these var changes or colors. And can set more than only the color, e.g. animations, sizes, etc. And can set on and of colors as you were asking for.

show_name: true
show_icon: true
show_state: true
type: glance
entities:
  - entity: sun.sun
    name: Ladekabel
    card_mod:
      style: 
        state-badge: 
          $: |
            ha-state-icon {
              color:red !important;
            }
1 Like

thanks :slight_smile:
It seems, that when Iā€™ve tried to use the css styles - I was starting from the wrong elementsā€¦ thatā€™s why it did not work when Iā€™ve tried thoseā€¦ (and therefore was also sticking to the varsā€¦)

seems, that I really need to do more card-mod stuff to get used to it :slight_smile:

Hi, is some alernative for --paper-item-icon-active-color please?
I need use this code, whitch not workiong after update to 2022.12.
Thank you.

      - type: state-icon
        entity: switch.sonoff_hlavice_obyvak
        title: Hlavice obĆ½vĆ”k
        tap_action:
          action: more-info
        style:
          top: 21%
          left: 81%
          transform: translate(-50%,-50%) rotate(-90deg)
        card_mod:
          style: |
            :host { 
            --paper-item-icon-active-color:
              {% if is_state('switch.boost_heating_obyvak', 'on') %}
                var(--paper-item-icon-active-color, #fdd835) !important
              {% elif is_state('switch.vetrani_obyvak', 'on') or is_state('binary_sensor.aqara_door_balkon', 'on') or is_state('binary_sensor.aqara_window_balkon', 'on') %}
                black !important
              {% elif is_state('switch.termostat_obyvak', 'on') %}
                var(--error-color) !important
              {% elif is_state('switch.sonoff_hlavice_obyvak', 'on') %}
                var(--warning-color) !important
              {% else %}
                var(--heat-color) !important
              {% endif %}
              ;
            --paper-item-icon-color:
              {% if is_state('switch.vetrani_obyvak', 'on') or is_state('binary_sensor.aqara_door_balkon', 'on') or is_state('binary_sensor.aqara_window_balkon', 'on') %}
                black !important
              {% else %}
                var(--primary-color) !important
              {% endif %}
              ;
            }

Have a look in the last posts. In short: Either use use direct coloring instead of manipulating the host vars or you have to manipulate the fitting new host var, which is now depending on class_type, etc.

Using variables (especially after 2022.12)

appears I didnt use the --paper-icon-active-color anywhere in my dashboards luckily (besides the earlier footer script button, which was solved by using the state-script-color variable). But, I do use the
--paper-item-icon-color in multiple places, in Folds

      - type: custom:fold-entity-row
        card_mod:
          style: |
            :host {
              color: {{'ivory' if states('sensor.next_alarm') == 'Not set' }};
              --paper-item-icon-color: {{'ivory' if states('sensor.next_alarm') == 'Not set' else
               'crimson' }};
            }

or on single entities (this one cant be changed by custom-ui, because made by a custom integration, so had to use card-mod on it in the dashboard):

            - entity: binary_sensor.backups_stale
              card_mod:
                style: |
                  :host {
                    --paper-item-icon-color:
                      {% if states(config.entity) == 'off' %} green
                      {% else %} red
                      {% endif %};

and am glad to be able to report at least that still works just as before.
not sure if this helps anyoneā€¦ yet there it is :wink:

I didnā€™t, I gave up :P.

Looking for some basic formatting help, please. With my limited CSS skills and failed searching, Iā€™ve been trying to combine the card_mod sections of the following two example cards.

ONE

type: custom:mushroom-media-player-card
entity: media_player.sonos_all_inside
use_media_info: true
card_mod:
  style:
    mushroom-state-info$: |
      .secondary:after {
        content: " | {{ state_attr(state_attr(config.entity, "active_child"), "friendly_name") }} + {{((state_attr((state_attr(config.entity, 'active_child')), 'group_members'))|list|count)-1 }}"
      }

TWO

type: custom:mushroom-media-player-card
entity: media_player.sonos_all_inside
use_media_info: true
card_mod:
  style: |
    ha-card {
      background: black; 
    }

So far, I canā€™t figure out the correct fromatting or maybe syntax that allows them to coexist.

For example, this doesnā€™t process the template to change mushroom-state-info:

card_mod:
  style: |
    mushroom-state-info$: |
      .secondary:after {
        content: " | {{ state_attr(state_attr(config.entity, "active_child"), "friendly_name") }} + {{((state_attr((state_attr(config.entity, 'active_child')), 'group_members'))|list|count)-1 }}"
      }
    ha-card {
      background: black; 
    }

And this fails to render the card at all:

card_mod:
  style:
    mushroom-state-info$: |
      .secondary:after {
        content: " | {{ state_attr(state_attr(config.entity, "active_child"), "friendly_name") }} + {{((state_attr((state_attr(config.entity, 'active_child')), 'group_members'))|list|count)-1 }}"
      }
    ha-card {
      background: black; 
    }

Thank you!

Trying to do a simple by studying your examples but no sucess. hope you can help. I have the following multiple entity row card inside swipe card

type: custom:swipe-card
reset_after: 10
cards:
  - type: entities
    entities:
      - type: custom:multiple-entity-row
        entity: binary_sensor.terrace_door
        secondary_info:
          attribute: battery
          name: Battery
          unit: 'V'

Now this looks like
image

I want to change the color of the whole secondary line in accordance with value of the battery %. Red when below 10
yellow when between 10 and 50
green above 50

1st post ā†’ link at the bottom ā†’ styles for ā€œmultiple-entity-rowā€.

Use jinjia templates.

tried but not able to pull it off.

Show your try and weā€™ll figure out, what was/is wrong.

I have checked the example and in it instead of attribute, the last_changed is used and so corresponding tag in style. what would be the tag for the attribute battery in my code? I am not able to get that.

If secondary_info is not a relative time - then there will be no a corresponding ā€œrelative timeā€ element, so apply a style to the parent element. Use Code Inspector.

Seriously, w/o personal attempts a user cannot learn anything. These examples are not for thoughtless copy/paste. Use this as a starting point:

  - type: entities
    entities:
      - type: custom:multiple-entity-row
        style:
          hui-generic-entity-row $: |
            .info.pointer .secondary {
              color: red;
            }
        entity: sun.sun
        entities:
          - entity: sun.sun
        name: Colored secondary_info
        secondary_info: xxxx

image

2 Likes

Hi guys. Any help with styling selectem div?


It is markdown card with ha-alert. Too many shadow roots for me to make it workā€¦ :frowning:

Tried this, but doesnā€™t work:

    ha-markdown$ ha-alert$: |
      div.icon.no-title {
        color: red:  
      }

Answering my own question in case anyone else is trying to do the sameā€¦

It was just basic formatting/indentation thwarting me. This works:

card_mod:
  style:
    mushroom-state-info$: |
      .secondary:after {
        content: " | {{ state_attr(state_attr(config.entity, "active_child"), "friendly_name") }} + {{((state_attr((state_attr(config.entity, 'active_child')), 'group_members'))|list|count)-1 }}"
      }
    .: |
      ha-card {
        background: black; 
      }

Iā€™ve managed to create this vertical stack card and have been able to style the elements within it. However, Iā€™m having an issue getting my card_mod styles to apply to the entire vertical stack (see code at the bottom). Iā€™ve tried numerous things but cannot get it to work. Any ideas whatā€™s wrong with my code?

Hereā€™s how the card looks currently. Ideally the background color changes to #457863.

image

type: vertical-stack
cards:
  - type: custom:mushroom-title-card
    title: |2-
                 {%- if now().hour < 12 -%}Morning
                 {%- elif now().hour < 18 -%}Afternoon
                 {%- else -%}Evening{%- endif -%}, {{user}}
    subtitle: >-
      ā™»ļø {{state_attr('calendar.bins', 'message')}} on {{
      as_timestamp(state_attr("calendar.bins","start_time") |
      default(now(),true) )| timestamp_custom('%-d %b') }}
  - type: horizontal-stack
    cards:
      - type: custom:mushroom-chips-card
        card_mod:
          style: |
            :host {
              padding-top: 10px;
              padding-left: 10px;
              padding-bottom: 25px;
              --ha-card-background: white;
            }
        chips:
          - type: action
            icon_color: red
            tap_action:
              action: navigate
              navigation_path: media-control
            icon: mdi:remote
            hold_action:
              action: none
            double_tap_action:
              action: none
          - type: action
            icon_color: blue
            tap_action:
              action: navigate
              navigation_path: audio
            icon: mdi:radio
          - type: action
            icon_color: blue-grey
            icon: mdi:radio
            tap_action:
              action: navigate
              navigation_path: media-settings
          - type: action
            icon_color: amber
            hold_action:
              action: none
            double_tap_action:
              action: none
            icon: mdi:lightbulb-group
            tap_action:
              action: navigate
              navigation_path: all-lights
          - type: action
            icon_color: green
            icon: mdi:timeline-clock
            hold_action:
              action: none
            double_tap_action:
              action: none
            tap_action:
              action: navigate
              navigation_path: automations
        alignment: justify
  - type: horizontal-stack
    cards:
      - type: custom:mushroom-person-card
        card_mod:
          style: |
            :host {
              padding-left:10px;
              --ha-card-background: #123456;
            }
        entity: person.alexander_benedet
        fill_container: true
        icon: mdi:face-man
        tap_action:
          action: navigate
          navigation_path: dan
        hold_action:
          action: none
        double_tap_action:
          action: none
      - type: custom:mushroom-person-card
        card_mod:
          style: |
            :host {
              padding-left:10px;
              --ha-card-background: #292589;
            }
        entity: device_tracker.nancy_phone
        fill_container: true
        icon: mdi:face-woman
card_mod:
  style: |
    ha-card {
      padding-left: 25px;
      padding-right: 25px;
      padding-bottom: 25px;
      background: #457863;
    }

The stack-cards donā€™t have a ha-card-element. So you can only style them (and any other card without ha-card element) with putting the cards into other cards with such an element. E.g. either with custom:mod-card or with HACS hui-element.