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

That isnā€™t valid CSS. Youā€™re mixing YAML and CSS. Is there a place that you got this code from?

Itā€™s a picture elements card - for which card-mod does not work, apparently.

Probably because it already has the ā€œstyleā€ key.

Iā€™m pretty familliar with css as well as controling them with JS. Existing of style property shoildnā€™t be any obstacle.

Is there a document over here which explain how card-mod work and why it is so complex task to style HA pages? Why there are cards which cannot be styled by card-mod while those are obviously stylable (as anyone can confirm using browser devtool).

Because of shadow roots and HA limitations. Try yourself to use the browser console to style a card.

Iā€™m using the Card-mod code below to select which elements are ā€œblurredā€ using the addon popup-backdrop-filter.
Example:
2

  card-mod-more-info-yaml: |
    $: |
      .mdc-dialog {
        backdrop-filter: blur(13px);
        -webkit-backdrop-filter: blur(13px);
        background: rgba(0,0,0,0.0);
      }
      .mdc-dialog .mdc-dialog__container .mdc-dialog__surface {
        border-radius: 1em;
      }

It does a great job with popups. However, I canā€™t figure out how to also blur the background when the card editor is open (see below screenshot). Could someone please assist me to also blur the card editorā€™s background? I havenā€™t been successful in finding the right element(s) to add to the code above.

This is what the card editor looks like currently:
Screenshot45

Thanks in advance for your time.

Mind asking over here instead?

This might be not possible yet, so I would encourage you to raise an issue over at card-mod, and possibly mention thomasloven (from what I can see theyā€™ve unwatched the repo).

Thanks for pointing me in the right direction to get help.

Is there a way to use card-mod in the following to reduce the font size for the name in last 4 buttons?

type: 'custom:vertical-stack-in-card'
cards:
  - type: thermostat
    entity: climate.living_room
    style: |
      ha-card {
        color: white;
        box-shadow: none;
        background:
        {% if is_state_attr('climate.living_room', 'hvac_action', 'heating') %}
          #EB6D00
        {% endif %} ;
        background: 
        {% if is_state_attr('climate.living_room', 'hvac_action', 'cooling') %}
          blue 
        {% endif %} ;
        background:
        {% if is_state_attr('climate.living_room', 'hvac_action', 'off') %}
          #373F48
        {% endif %} ;
      }
    theme: iOS Dark Mode
  - type: entities
    entities:
      - entity: sensor.living_room_humidity
        name: Inside Humidity
        icon: 'hass:none'
      - entity: sensor.openweathermap_temperature
        name: Outside Temp.
        icon: 'hass:none'
    style: |
      ha-card {
        color: white;
        box-shadow: none;
        background:
        {% if is_state_attr('climate.living_room', 'hvac_action', 'heating') %}
          #EB6D00
        {% endif %} ;
        background: 
        {% if is_state_attr('climate.living_room', 'hvac_action', 'cooling') %}
          blue 
        {% endif %} ;
        background:
        {% if is_state_attr('climate.living_room', 'hvac_action', 'off') %}
          #373F48
        {% endif %} ;
      }
  - type: horizontal-stack
    cards:
      - type: 'custom:button-card'
        entity: input_select.hvac_mode
        name: MODE
        show_name: true
        tap_action:
          action: call-service
          service: input_select.select_next
          service_data:
            entity_id: input_select.hvac_mode
        color_type: icon
        state:
          - operator: template
            value: |
              [[[ return states['climate.living_room'].state === 'off' ]]]
            icon: 'mdi:power'
            color: white
          - operator: template
            value: |
              [[[ return states['climate.living_room'].state === 'heat' ]]]
            icon: 'mdi:fire'
            color: 'rgb(239, 140, 0)'
          - operator: template
            value: |
              [[[ return states['climate.living_room'].state === 'cool' ]]]
            color: blue
            icon: 'mdi:snowflake'
        styles:
          card:
            - background-color: |
                [[[
                  if (states['climate.living_room'].attributes.hvac_action == 'heating') 
                    return '#EB6D00';
                  if (states['climate.living_room'].attributes.hvac_action == 'cooling')
                    return 'blue';
                  else return '#373F48';
                ]]]
            - color: white
        show_state: false
      - type: 'custom:button-card'
        entity: input_select.preset_mode
        name: ECO
        label: ECO
        tap_action:
          action: call-service
          service: input_select.select_next
          service_data:
            entity_id: input_select.preset_mode
        color_type: icon
        color: white
        icon: 'mdi:leaf-off'
        state:
          - operator: template
            value: >
              [[[ return states['climate.living_room'].attributes.preset_mode ==
              'eco' ]]]
            icon: 'mdi:leaf'
            color: green
        show_state: false
        show_name: true
        styles:
          card:
            - background-color: |
                [[[
                  if (states['climate.living_room'].attributes.hvac_action == 'heating') 
                    return '#EB6D00';
                  if (states['climate.living_room'].attributes.hvac_action == 'cooling')
                    return 'blue';
                  else return '#373F48';
                ]]]
            - color: white
      - type: 'custom:button-card'
        entity: climate.living_room
        name: SCHEDULE
        action: url
        navigation_path: 'https://home.nest.com'
        color_type: card
        icon: 'mdi:calendar-clock'
        show_state: false
        show_name: true
        styles:
          card:
            - background-color: |
                [[[
                  if (states['climate.living_room'].attributes.hvac_action == 'heating') 
                    return '#EB6D00';
                  if (states['climate.living_room'].attributes.hvac_action == 'cooling')
                    return 'blue';
                  else return '#373F48';
                ]]]
            - color: white
      - type: 'custom:button-card'
        entity: climate.living_room
        name: HISTORY
        action: url
        navigation_path: 'https://home.nest.com'
        color_type: card
        icon: 'mdi:progress-clock'
        show_state: false
        show_name: true
        styles:
          card:
            - background-color: |
                [[[
                  if (states['climate.living_room'].attributes.hvac_action == 'heating') 
                    return '#EB6D00';
                  if (states['climate.living_room'].attributes.hvac_action == 'cooling')
                    return 'blue';
                  else return '#373F48';
                ]]]
            - color: white

2 Likes

You should ask over at button-card, they have built-in styling. Or just read the docs of it over at GitHub.

Thanks. First time trying to use card-mod. Iā€™ve read the docs and I guess Iā€™m missing something. Does card-mod (or mod-card) need to be specified as a card type above the card(s) you want to inject styling into? I tried adding styling but nothing happened so I presume thatā€™s what needs to be done now that I think more about it. Iā€™ll have another go at itā€¦

I did not know there was a Github Community Support forum. Now I do! Posted a new topicā€¦

I figured it out, finally!

      - type: 'custom:button-card'
        style: |
          ha-card { 
            font-size: 0.8rem
            }

Well, I thought I had.
The ha-card entry is being overridden by a constructed stylesheet called ha-card.button-card-main { .

UPDATE: added !important to the font entry and that fixed it.

Grid Card - is there any way to reduce the space between cards in new grid card?

Bumping my own question since it hasnā€™t been fixed/reverted with HA117 updates or HA 118 and I havenā€™t found a workaround yet. I can confirm that the !important does not work ideally here. Each time you refresh the tab, first the stylesheet is applied and then the css cardmod, which causesthe markdown styling to jump which makes using the interface a bad experience.

Iā€™m not skilled with CSS, but perhaps there is a way to change (or delete) the stylesheet itself.

Github ticket: https://github.com/home-assistant/frontend/issues/7578#issuecomment-720539351

Can i change the color of my title only with this?

I tried

style: |
          ha-card {
            --primary-text-color: #e79118
          }

But that changed all my text
title-color doesnt work

Thereā€™s a regular theme variable for that, something like grid-card-gap, no need for card-mod, use it as a regular theme variable.

1 Like

Which card are you using?

stack in card
But when i do, it changes the title but also the text under the cards that are in stack

If i add another style to those card in stack, it works, but its wrong color, mm

When I get out of work, Iā€™ll see which element you need to target to change the title color. Could you use the HTML font tag for changing the color?

Could you use the markdown card with the font HTML tag for that, instead of using the header?