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

Hi! Could anyone help me out? If you look at my picture the 2nd weather card is ā€œgoodā€ but this is one using an other entity which doesnt work with tap_action. So i wanted to add a other weather card which supports tap_action but the scaling is bad ( the one above ) it should be like the 2ndā€¦

type: custom:stack-in-card
cards:
  - type: custom:layout-card
    layout_type: custom:grid-layout
    layout:
      grid-template-columns: auto auto
      margin: 8px 4px 4px 4px;
    cards:
      - type: custom:mushroom-chips-card
        chips:
          - type: entity
            entity: person.laurens
            content_info: none
            use_entity_picture: true
            card_mod:
              style: |
                /* Color border around avatar to show person status */
                ha-card {
                  --chip-background:
                  {% if is_state(config.entity, ['home', 'not_home', 'unknown']) %}
                    rgb(var(--rgb-state-person-{{ states(config.entity) | replace('_', '-') }} ))
                  {% else %}
                    rgb(var(--rgb-state-person-zone))
                  {% endif %};
                } 
                /* Slightly enlarge & bring to front on hover */
                ha-card:hover {
                  transform: scale(1.2);
                  transform-origin: top center;
                  z-index: 1;
                  transition: all 1s;
                }
          - type: entity
            entity: person.adna
            content_info: none
            use_entity_picture: true
            card_mod:
              style: |
                /* Color border around avatar to show person status */
                ha-card {
                  --chip-background:
                  {% if is_state(config.entity, ['home', 'not_home', 'unknown']) %}
                    rgb(var(--rgb-state-person-{{ states(config.entity) | replace('_', '-') }} ))
                  {% else %}
                    rgb(var(--rgb-state-person-zone))
                  {% endif %};
                } 
                /* Slightly enlarge & bring to front on hover */
                ha-card:hover {
                  transform: scale(1.2);
                  transform-origin: top center;
                  z-index: 1;
                  transition: all 1s;
                }
          - type: template
            entity: input_boolean.jax_home_not_home
            picture: local/images/jax.jpg
            hold_action:
              action: none
            double_tap_action:
              action: none
            card_mod:
              style: |
                /* Color border around avatar to show person status */
                ha-card {
                  {% if is_state(config.entity, 'on') %}
                    --chip-background: rgb(var(--rgb-state-person-home));
                  {% else %}
                    --chip-background: red; /* Set to red when the status is 'off' */
                  {% endif %};
                } 
                /* Slightly enlarge & bring to front on hover */
                ha-card:hover {
                  transform: scale(1.2);
                  transform-origin: top center;
                  z-index: 1;
                  transition: all 1s;
                }
          - type: template
            entity: input_boolean.gasten_modus
            icon: mdi:account-plus
            hold_action:
              action: none
            double_tap_action:
              action: none
            card_mod:
              style: |
                /* Color border around avatar to show person status */
                ha-card {
                  {% if is_state(config.entity, 'on') %}
                    --chip-background: rgb(var(--rgb-state-person-home));
                  {% else %}
                    --chip-background: red; /* Set to red when the status is 'off' */
                  {% endif %};
                } 
                /* Slightly enlarge & bring to front on hover */
                ha-card:hover {
                  transform: scale(1.2);
                  transform-origin: top center;
                  z-index: 1;
                  transition: all 1s;
                }
        alignment: end
        card_mod:
          style: |
            ha-card { 
              /* Overlap avatar Chips */
              --chip-spacing: calc(-1 * var(--mush-chip-spacing, 8px));

              /* Set size of border around Chips */
              --chip-avatar-padding: 2px;

              /* Reduce width to fit Chips & allow max space for weather */
              width: fit-content;
              transition: all 0s;
            }
      - type: weather-forecast
        show_current: true
        show_forecast: false
        entity: weather.buienradar
        forecast_type: daily
        theme: Mushroom Shadow
        name: ' '
        tap_action:
          action: fire-dom-event
          browser_mod:
            service: browser_mod.popup
            data:
              title: Weersverwachting
              content:
                type: entities
                entities:
                  - type: custom:weather-card
                    entity: weather.forecast_home
                    forecast: true
                    details: false
        card_mod:
          style:
            .: |
              ha-card {
                --ha-card-background: none;
                --ha-card-box-shadow: none;
                --ha-card-border-width: 0;
                padding: 5px !important;
              }
              .current{
                font-size: 6px;
              }

How can I get the 1 and 2 lower ?

afbeelding

            card_mod:
              style: |
                ha-card {
                    position: fixed;
                    bottom: 0;
                    left: 0;
                    width: 100%;
                    display: flex;
                    justify-content: center;
                    padding-bottom: 0px
                }   

Hi and thank you a lot for being so patient and willing to help! This is highly appreciated!

Iā€™d be happy if anyone could have a look at my problem.
Goal: I like to have the font of a glance card bold as well as the margin between icon and text to a defined value.
Both things work separately (thanks to this forum):

        card_mod:
          style: |
              ha-card {
                font-weight: bold
              }

leads to bold font::
Bildschirmfoto vom 2024-02-09 12-16-08

and:

          card_mod:
            style:
              .entities .entity:
                $: |
                  state-badge {
                    margin-top: 50px;
                    margin-bottom: 0px;
                  }

leads to an adjustable margin:
Bildschirmfoto vom 2024-02-09 12-14-49

I donā€™t understand anything of CSS coding style, but I really tried many many combinations - no chance.

So how do I combine both?

Thanks a lot in advance!

Is this what you are after?

card_mod:
     style:
        .entities .entity:
           $: |
            state-badge {
               margin-top: 15px;
               margin-bottom: 0px;
                 }
        .:  |
          ha-card {
           font-weight: bold;
                 }

Awesome, thank you!
Bildschirmfoto vom 2024-02-09 13-02-39
I really should try to understand that :see_no_evil:

The code above has been applied to glance cards. Do you also know how to do it for button cards? And if yes: where can I find this information by myself?

Cheers

Here

Yes, I already came across that one. But I hoped that it would be possible without installing an additional custom card type.
But doesnā€™t it make the approach to use CSS styling on build-in cards obsolete if one installs dedicated card that fulfill the desired features?

From my point of view it is more ā€œconsistentā€ to stick to one approach. :thinking:

I misunderstoodā€¦Iā€™m not sure about the standard button card. Didnā€™t see much in the guide on this post when reading through it.

I had actually tried changing the margin in both the template and directly on the button and it didnā€™t do anything.

Iā€™ll give that a shot. Thanks

Alright, no problem. Thank you anyway! :+1:

just found the header link icon in history-graph cards, and tbh, it was unthemed, and didnt look nice at all.
So, I wanted to hide it, which works with display: none.
Add a boolean toggle, and control it from the UI.

next I needed it to be in style with my themes, so set primary-color on the icon. seems nice:

    .card-header ha-icon-button {
      --card-mod-icon-color: var(--primary-color);
      {{'display: none' if is_state('input_boolean.hide_history_graph_link','on')}};
    }

if would hope to find a theme variable for the icon, so we wont need to see it in a card_mod for each individual card.

Did anyone find that yet?

default icon:

no icon:

themed icon:

Hi Ildar, excelent work!

Ildar, Iā€™m trying to remove/hide without success the component

for "custom:more-info-card"

Iā€™ve also been trying for some time to reduce the height of the entire component by half.

Can you help me with this?

type: horizontal-stack
cards:
  - type: custom:more-info-card
    entity: light.spots_da_tv
    title: Spots TV
    card_mod:
      style: |
        ha-card {
          width: 150px;
          state-card-content {
            display:none;
          }
        }   

Can you post your code so folks can copy and paste it easily? It helps expedite solutions.

#11

After upadate Core,the color of this icon doesnā€™t work. this is a bug or am i wrong?

type: horizontal-stack
cards:
  - type: tile
    entity: sensor.aria_pm25
    name: PM 2.5
    show_entity_picture: false
    card_mod:
      style:
        .icon-container .icon$: |
          .shape { 
            border-radius: 15px !important;
            background:
              {% if states('sensor.aria_pm25')|float(0) >= 125|float(0) -%}
                rgba(255,0,0,0.6)
              {% elif states('sensor.aria_pm25')|float(0) >= 60|float(0) -%}
                rgba(255,165,0,0.8)
              {% elif states('sensor.aria_pm25')|float(0) >= 0|float(0) -%}
                rgba(60,179,113,0.6) 
              {% endif %} !important; 
          }
  - type: tile
    entity: sensor.aria_voc_index
    name: VOC Index
    icon: mdi:chart-bell-curve-cumulative

Noticed similar things occurring with tile card icons and animations since the update. Change:

.icon-container .icon$

with:

ha-tile-icon$

Has fixed some issues for me

1 Like

I think the DOM path has changed slightly, so that the tile icon element no longer has the .icon class. Try this to see if it works for you (it does for me):

    card_mod:
      style:
        .icon-container ha-tile-icon $: |

Actually, not sure you really need the .icon-container bit. Try this alternatively:

    card_mod:
      style:
        ha-tile-icon $: |

EDIT: gbboy got there first!

1 Like

yes, it is work!!! thank you

yes, this is the solution, itā€™s work! thanks

@hazio What card? Check out