Mushroom Cards Card Mod Styling/Config Guide


For some reason, even copying cards that are “ready” they still show the icon as small. This has been like this for over a year, I’ve tried fixing it, gave up, tried, gave up, tried, gave up, and now I’m gonna try again.

My Home Assistant can’t seem to reproduce the same way. What can I be doing wrong?!
The first screenshot is a recently “adapted” card and the icon still shows very small compared to the cards people been working on.

I’ve even tried reverting to the 3.4.4 version, still same results. Can’t even revert to the point they look like they were (with the big icon, I’m pretty sure you understand what I mean).

Guys, I’m sorry but I’m really lost lol. I’ve read this entire thread and no results. Tried over 10 cards, nothing. It has to be something so silly that I can’t even think off

Older card example:

type: custom:stack-in-card
cards:
  - type: custom:mushroom-template-card
    entity: input_boolean.room_attic
    primary: Sotão
    secondary: |
      {{ states('sensor.temp_attic') | round(0) }}°C | {{
      states('sensor.humd_attic') | round(0) }}%
    icon: mdi:home-roof
    tap_action:
      action: navigate
      navigation_path: attic
    hold_action:
      action: call-service
      service: light.turn_off
      data:
        transition: 3
      target:
        area_id: attic
    double_tap_action:
      action: toggle
    icon_color: |-
      {% if states('light.candeeiro_sotao') == 'on' %}
      #FFB300
      {% endif %}
    fill_container: true
    layout: horizontal
    multiline_secondary: false
    card_mod:
      style: |
        ha-card([dark-mode]) {
          background: rgba(var(--rgb-primary-background-color), 0.25);
        } 

        ha-card {
          background: rgba(var(--rgb-primary-text-color), 0.025);
          --icon-size: 76px;
          margin-top: -20px !important;
          margin-left: -18px !important;
          margin-bottom: -11px !important;
        }
  - type: custom:mushroom-chips-card
    chips:
      - type: conditional
        conditions:
          - entity: binary_sensor.occupancy_attic
            state: "on"
        chip:
          type: template
          icon_color: disabled
          icon: mdi:transition
          tap_action:
            action: none
          hold_action:
            action: none
      - type: conditional
        conditions:
          - entity: binary_sensor.window_attic_contact
            state: "on"
        chip:
          type: template
          icon_color: disabled
          icon: mdi:window-open-variant
          tap_action:
            action: none
          hold_action:
            action: none
      - type: conditional
        conditions:
          - entity: binary_sensor.attic_door_contact
            state: "on"
        chip:
          type: template
          icon_color: disabled
          icon: mdi:door-open
          tap_action:
            action: none
          hold_action:
            action: none
    alignment: end
    card_mod:
      style: |
        ha-card {
          --chip-box-shadow: none;
          --chip-background: none;
          --chip-spacing: 0;
          --chip-border-width: 0;
          position: relative;
          top: -20px;
        }
card_mod:
  style: |
    ha-card {
      height: 102px;
      {% if is_state('light.candeeiro_sotao', 'on') %}
        background: rgba(255, 179, 0, 0.1);
      {% endif %}
    }
    :host {
      background: var(--card-background-color);
      border-radius: var(--ha-card-border-radius);
    }

Code that I tried from a post up here but looks similar (broken) - but that seems to work for everyone else: (I know this one is vertical but I’m really just trying to understand what’s going on).

type: custom:stack-in-card
mode: horizontal
cards:
  - type: custom:mushroom-template-card
    icon: mdi:sofa
    icon_color: |-
      {% if states('light.night_stand') == 'on' or 
            states('switch.detached_garage_lights') == 'on' or 
            states('media_player.shield') == 'playing' or 
            states('light.pc_light') == 'on' %}
        light-blue
      {% else %}
        light-grey
      {% endif %}
    primary: Wohnzimmer
    secondary: "{{ states('sensor.living_room_temperature') | round(0)}}°C"
    layout: horizontal
    fill_container: false
    multiline_secondary: false
    entity: light.pc_lights
    tap_action:
      action: navigate
      navigation_path: badezimmer
    card_mod:
      style:
        mushroom-state-info$: |
          .primary {
            font-size: 16px !important;
            position: relative;
            top: -52px;
            left: -155px;
            overflow: visible !important;
            white-space: normal !important;
               }
          .secondary {
            position: relative;
            overflow: visible !important;
            font-weight: 500 !important;
            top: -50px;
            left: -145px;
            color:   {{ 'red' if states('sensor.basement_sensor_humidity') | int(0) <= 20 else 'yellow'}} !important;
             
             }
          .secondary:after {
            content: "{{states('sensor.basement_sensor_humidity')}}%";
            position: absolute;
            top: 0px;
            left: 50px;
            color:   {{ 'blue' if states('sensor.basement_sensor_humidity') | int(0) <= 20 else 'red'}} !important;
            }
        mushroom-shape-icon$: |
          .shape {
            left: -35px;
            top: 55px;
            --icon-symbol-size: 80px;
            --icon-size: 146px;
              }
        .: |
          ha-card {
           background: none !important;
           border-style: none !important;}
  - type: custom:mushroom-chips-card
    chips:
      - type: template
        entity: switch.detached_garage_lights
        tap_action:
          action: toggle
        icon: mdi:lightbulb
        hold_action:
          action: more-info
        icon_color: |-
          {% if is_state(entity, 'on') %} 
            amber 
          {% else %}
            light-grey
          {% endif %}
        double_tap_action:
          action: none
        card_mod:
          style: |
            ha-card {
             background: none !important;
             }
      - type: template
        entity: light.corner_stand
        icon: mdi:lightbulb-group
        icon_color: |-
          {% if is_state(entity, 'on') %} 
            amber
          {% else %}
           light-grey
          {% endif %}
        tap_action:
          action: toggle
        hold_action:
          action: more-info
        card_mod:
          style: |
            ha-card {
             background: none !important;
             }
      - type: template
        entity: light.night_stand
        icon: mdi:floor-lamp
        icon_color: |-
          {% if is_state(entity, 'on') %} 
            amber
          {% else %}
           light-grey
          {% endif %}
        tap_action:
          action: toggle
        hold_action:
          action: more-info
        card_mod:
          style: |
            ha-card {
             background: none !important;
             }
      - type: template
        entity: media_player.shield
        icon: mdi:television
        icon_color: |-
          {% if is_state(entity, 'playing') %} 
            blue
          {% else %}
           light-grey
          {% endif %}
        tap_action:
          action: more-info
        card_mod:
          style: |
            ha-card {
             background: none !important;
             }
    card_mod:
      style: |
        ha-card {
          width: 66px;
          margin-left: 60%;
          background: none !important;
          --chip-border-width: 0;
        }
card_mod:
  style: |
    ha-card {
     background: none !important;
     border: none;
       }

I had asked for help here but was hopeful that in a year or so I’d eventually understand. I didn’t. It’s been a year and half. I barely use my HA at this point cus I can’t fix it and I don’t wanna start over either lol.

Hi everybody,

I am currently discovering the advanced features of Mushroom CardMods!

Now I’m facing the following problem: I want to visualise the status of the window (open/closed/tilted) in the Shutter Card using a coloured ring around the roller shutter icon. Below code gives me the ring – exaggeratedly thick for clarity – but only half of it is in the desired colour. The other half is displayed in dark.:thinking:

card_mod:
  style:
    mushroom-shape-icon$: |
      .shape {
        border: 18px outset green;
      }

Would anybody know how to get a single-colour ring?

Thanks
Johannes

P. S. @dimitri.landerloos , I couldn’t find much about the border command in your fantastic explanations. Maybe you have an idea though?

Perhaps try adding !important to --icon-size.

Also, if you have been upgrading/downgrading etc, make sure to check out recommendations at Issues after upgrading any version - 3.x.x, 4.x.x · Issue #525 · thomasloven/lovelace-card-mod · GitHub

The darkness you see is because you are using Outset, you can use a different style to achieve a different effect:

You probably just want to change it to solid :slight_smile:

Thank you so much! :+1:

Amazing how easy it can be to adjust the views - provided one knows how to do it. :innocent:

TL;DR: For my mushroom template cards, I can move icon symbol size to ha-state-icon… but not icon-size.

I’ve got some mushroom cards set up to use for navigation… and I’m finding that I can set icon color as a template and style the icon symbol size and icon size… but the moment I try to include icon color in CSS (so I can use my template variables), I can’t do it.

This code:

type: custom:mushroom-template-card
entity: null
primary: BATTERIES
secondary: >
  {% set total = states('sensor.total_batteries') %} {% set count =
  states('sensor.devices_with_low_battery_level') | int %} {% if count > 0 %} {{
  count }} low level {% else %} {{ total }} monitored {% endif %}
icon: |
  {% if states('sensor.devices_with_low_battery_level') | int > 0 %}
    mdi:battery-alert-variant-outline
  {% else %}
    mdi:battery-high
  {% endif %}
icon_color: |
  {% if states('sensor.devices_with_low_battery_level') | int > 0 %}
    red
  {% else %}
    green
  {% endif %}
badge_icon: ""
badge_color: ""
layout: vertical
tap_action:
  action: navigate
  navigation_path: /batteries
hold_action: none
card_mod:
  style:
    mushroom-state-info$: |
      .container {
        --card-primary-color: var(--primary-text-color);
        --card-secondary-color: var(--primary-text-color);
      }
    mushroom-shape-icon$: |
      .shape {
        --icon-symbol-size: 35px;
        --icon-size: 50px;
      }
    .: |
      ha-card {
        background-color: var(--secondary-background-color);
        --card-primary-font-size: 18px;
        --card-secondary-font-size: 16px;
      }

…gives me this:

…but try as I might, when I include icon color in card_mod, things go bad:

type: custom:mushroom-template-card
entity: null
primary: BATTERIES
secondary: >
  {% set total = states('sensor.total_batteries') %} {% set count =
  states('sensor.devices_with_low_battery_level') | int %} {% if count > 0 %} {{
  count }} low level {% else %} {{ total }} monitored {% endif %}
icon: |
  {% if states('sensor.devices_with_low_battery_level') | int > 0 %}
    mdi:battery-alert-variant-outline
  {% else %}
    mdi:battery-high
  {% endif %}
icon_color: |
  {% if states('sensor.devices_with_low_battery_level') | int > 0 %}
    red
  {% else %}
    green
  {% endif %}
badge_icon: ""
badge_color: ""
layout: vertical
tap_action:
  action: navigate
  navigation_path: /batteries
hold_action: none
card_mod:
  style: |
    ha-state-icon {
      color: green;
        --icon-symbol-size: 35px;
    }
    mushroom-state-info$: |
      .container {
        --card-primary-color: var(--primary-text-color);
        --card-secondary-color: var(--primary-text-color);
      }
    mushroom-shape-icon$: |
      .shape {
        --icon-size: 50px;
      }
    .: |
      ha-card {
        background-color: var(--secondary-background-color);
        --card-primary-font-size: 18px;
        --card-secondary-font-size: 16px;
      }

I must be doing something wrong with my card_mod ordering or syntax, because I’m running into a similar issue with my climate cards. I can’t set background color and icon color simultaneously.

I have this:

…coded as such:

card_mod:
  style: |
    ha-card {
    {% if is_state('climate.heat_pump_basement', 'heat') %} 
      background-color: var(--background-hvac-heat);
    {% elif is_state('climate.heat_pump_basement', 'cool') %} 
      background-color: var(--background-hvac-cool);
    {% elif is_state('climate.heat_pump_basement', 'dry') %} 
      background-color: var(--background-hvac-dry);
    {% elif is_state('climate.heat_pump_basement', 'fan_only') %} 
      background-color: var(--background-hvac-fan);
    {% else %}
      background-color: var(--background-hvac-off);
    {% endif %}
      --card-primary-font-size: 16px;
      --card-secondary-font-size: 14px;
      --card-primary-color: var(--primary-text-color);
      --card-secondary-color: var(--primary-text-color);
      --primary-text-color: var(--primary-text-color);
    }

…and I want to set the buttons to the same color as the temperature setpoint, so I edit to add this:

    mushroom-climate-temperature-control$:
      mushroom-input-number$: |
        #container .button:nth-child(1) {
          --card-mod-icon-color: var(--primary-text-color);
        } #container .button:nth-child(3) {
          --card-mod-icon-color: var(--primary-text-color);
        } }
    ha-card {
    {% if is_state('climate.heat_pump_basement', 'heat') %} 
      background-color: var(--background-hvac-heat);
    {% elif is_state('climate.heat_pump_basement', 'cool') %} 
      background-color: var(--background-hvac-cool);
    {% elif is_state('climate.heat_pump_basement', 'dry') %} 
      background-color: var(--background-hvac-dry);
    {% elif is_state('climate.heat_pump_basement', 'fan_only') %} 
      background-color: var(--background-hvac-fan);
    {% else %}
      background-color: var(--background-hvac-off);
    {% endif %}
      --card-primary-font-size: 16px;
      --card-secondary-font-size: 14px;
      --card-primary-color: var(--primary-text-color);
      --card-secondary-color: var(--primary-text-color);
      --primary-text-color: var(--primary-text-color);
    }

…and end up with this:

could you simplify that first? just use red or some other significant color to spot, and maybe add !important.

if you get that to work, then add the templates.
makes it easier to debug

Right you are… I was encouraged that at least the templates were working because I was seeing my changes… but other mods were being undone at the same time.

So, this results in a red background:

card_mod:
  style: |
    ha-card {
      background-color: red;
    --card-primary-color: var(--primary-text-color);
    --card-secondary-color: var(--primary-text-color);
    --primary-text-color: var(--primary-text-color);
    }

…and it appears this added code to change button color isn’t doing anything at all:

card_mod:
  style: |
    ha-card {
      background-color: red;
    --card-primary-color: var(--primary-text-color);
    --card-secondary-color: var(--primary-text-color);
    --primary-text-color: var(--primary-text-color);
    }
    mushroom-climate-temperature-control$:
      mushroom-input-number$: |
        #container .button:nth-child(1) {
          --card-mod-icon-color: purple;
        } #container .button:nth-child(3) {
          --card-mod-icon-color: purple;
        } 

EDIT: I tried adding !important between these color names and the semi-colon to no effect.

Not at desk now, but it seems you combine those 2 incorrectly

What happens if you add the ha-card after a .: | and not directly after the style:

Or, test that without the complete ha-card

And take out the |

edit

I meant like this:

card_mod:
  style:
    .: |
      ha-card {
        background-color: red;
      --card-primary-color: var(--primary-text-color);
      --card-secondary-color: var(--primary-text-color);
      --primary-text-color: var(--primary-text-color);
    }
    mushroom-climate-temperature-control$:
      mushroom-input-number$: |
        #container .button:nth-child(1) {
          --card-mod-icon-color: purple;
        } #container .button:nth-child(3) {
          --card-mod-icon-color: purple;
        } 

I didnt check any of the selectors, just the syntax for combining modifications to $: and final .:

1 Like

Deleting my comment and editing for clarity…

A direct copy from @dimitri.landerloos’s original post (with my colors inserted) works:

card_mod:
  style:
    mushroom-climate-temperature-control$:
      mushroom-input-number$: |
        #container .button:nth-child(1) {
          --card-mod-icon-color: purple;
        }
        #container .button:nth-child(3) {
          --card-mod-icon-color: purple;
        }

Unfortunately, I don’t know the name of that button on the right side to alter the color of that. But that aside… I’m still unable to get the button color and card background color to work simultaneously. I’ve tried the suggestions you made above to no avail… your code above results in the background turning red, but default button colors.

card_mod:
  style:
    mushroom-climate-temperature-control$:
      mushroom-input-number$: |
        #container .button:nth-child(1) {
          --card-mod-icon-color: purple;
        }
        #container .button:nth-child(3) {
          --card-mod-icon-color: purple;
        }
    mushroom-button$: |
      .button  ::slotted(*) {
        --card-mod-icon-color: orange;
      }        
    .: |
      ha-card {
        background: red;
      }

Even got that last button for you :wink:


Dont mind the snow flakes, my wife loves the new experimental feature :slight_smile:

1 Like

That’s outstanding! :smiley:

I’m still seeing some strange behavior using theme variables for colors. This works great:

card_mod:
  style:
    mushroom-climate-temperature-control$:
      mushroom-input-number$: |
        #container .button:nth-child(1) {
          --card-mod-icon-color: white;
        }
        #container .button:nth-child(3) {
          --card-mod-icon-color: white;
        }
    mushroom-button$: |
      .button  ::slotted(*) {
        --card-mod-icon-color: white;
      }        
    .: |
      ha-card {
        background-color: var(--background-hvac-heat);
        --card-primary-font-size: 16px;
        --card-secondary-font-size: 14px;
        --card-primary-color: var(--primary-text-color);
        --card-secondary-color: var(--primary-text-color);
        --primary-text-color: var(--primary-text-color);
      }

…but this does not:

card_mod:
  style:
    mushroom-climate-temperature-control$:
      mushroom-input-number$: |
        #container .button:nth-child(1) {
          --card-mod-icon-color: var(--primary-text-color);
        }
        #container .button:nth-child(3) {
          --card-mod-icon-color: white;
        }
    mushroom-button$: |
      .button  ::slotted(*) {
        --card-mod-icon-color: white;
      }        
    .: |
      ha-card {
        background-color: var(--background-hvac-heat);
        --card-primary-font-size: 16px;
        --card-secondary-font-size: 14px;
        --card-primary-color: var(--primary-text-color);
        --card-secondary-color: var(--primary-text-color);
        --primary-text-color: var(--primary-text-color);
      }

??

The only change here is in line 6. Note that my primary-text-color is white in this theme.

This CSS declaration is causing you to lose --primary-text-color as its a cyclic reference to self. See CSS Custom Properties for Cascading Variables Module Level 1. Remove this and all will work as expected.

2 Likes

It does! I should have picked up on that… that’s what using find+replace gets me…

Thanks.

Since ive got you here, i know it might be a massive breaking change, unless you wrote it with backwards compatibility in mind. But is there any consideration to changing how .: Works?

I find that it confuses so many people. Is there no way for us to achieve a list of style instead? So something like this:

card_mod:
  style: |
    ha-card {
      background: red;
    }
  style:
    mushroom-shape-icon$: |
      .shape {
        background: red;
      }

Or if need be like:

card_mod:
  - style: |
      ha-card {
        background: red;
      }
  - style:
      mushroom-shape-icon$: |
        .shape {
          background: red;
        }

I think this would be far less confusing for people, but of course i dont know what effect that might have on how card mod is attached to the DOM.

1 Like

tbh, that is really ugly… :wink:

and it would still need users to understand where the element resides in the Dom. Final, or Shadow.
So no advantage in that regard either?

The fact it confuses people is because they c&p, instead of trying to understand. Did you follow the thread on deprecation of platform: template…? 1000+ posts in 2 weeks…

Ive said it there, and could repeat here: the fact people panic now and keep asking the same questions over and over is a serious red flag, how do they manage their systems at all.

Dont have the docs of card-mod from the top of my head, but, if not yet there, a very small instruction/explanation could be helpful, smt like this added to the Dom navigation explanation, or even the new readme-application?:

Final vs Shadow elements:

  • Final (. / direct style): Styles the card’s main (light DOM) element, e.g. ha-card.
  • Shadow ($): Styles elements inside the card’s shadow DOM (internal elements).
  • Combined: Use both to style the card itself and its internal shadow elements in one config.

Overview & how to use

  • Final (light DOM):
    Styles the card container itself (e.g. ha-card).
card_mod:
  style: |
    ha-card { }
  • Shadow (shadow DOM):
    Styles elements inside the card’s shadow DOM (internal elements).
card_mod:
  style:
    $: |
      .shadow-element { }
  • Final + Shadow together:
    Use when you need to style both the card container and its internal elements.
card_mod:
  style:
    .: |
      ha-card { }
    $: |
      .shadow-element { }

.shadow-element is a placeholder name representing any internal element inside the card’s shadow DOM.

thats about it?
as said, users should still try to grasp what they are modifying in the first place…otherwise this still would be without meaning to them.

3 Likes

I agree with you - but trying to make it as user friendly as possible is probably still a good idea.

Im not suggesting that what ive said is the best solution by any means lol.

For someone like you and i, it might seem pretty self explanatory, but for someone who has never dealt with CSS it can be a bit complicated with how it currently works.
But you are right, just having a more thorough explanation in the readme would probably go a long way.

There is an explanation in the readme, but its burried within the example of the dom navigation section, and honestly it doesnt do a great job explaining why its needed:

GitHub - thomasloven/lovelace-card-mod: 🔹 Add CSS styles to (almost) any lovelace card

No. It works and is well documented. My view is that if a user needs to get to grips with $ I think they can also get to grips with .:.

The same users who may not understand .: may also have trouble with lists in yaml. Also, this does not solve another card_mod learning path, of when to use | or not. Then there is also the question of what to do with a style list item that share the same dict key. Is this to be merged, or kept separate? If a user is just cobbling together different style list items in hope it works, they may not see or understand the clashes they are including. Then does this method mandate that all yaml keys are separate? Stylistically it suggests so, but having a yaml key together versus apart is a technical imperative to how selection by yaml key works (i.e. when a card_mod element is applied).

Overall, I don’t see any overarching benefit of the proposal, with lots of potential downsides as well.

Documentation PRs more than welcome :pray:

1 Like