🔹 Card-mod - Add css styles to any lovelace card

I almost figured it out, but I’m probably setting the style in the wrong place, anyone that can point me to the right direction.
code:

 - type: 'custom:auto-entities'
        card:
          type: custom:layout-card
          layout_type: masonry
          layout:
            width: 100
            max_cols: 7
          style: |
            .column > * {
              margin: 10px !important;
            }
        filter:
          include:
            - domain: light
              options:
                type: custom:button-card
                template: 
                  - light
                  - icon_hue     
                entity_id: this.entity_id
          exclude:
            - state: "unavailable"

I’m trying to overwrite the margin element on the “column > *”


If I manually change it in the “developer tools” to margin: 10px !important;
I get the result I want, however if I place it in the code as you can see, the old value for margin is still applied. (I don’t see my change)

Hello
I would like to add the last_changed status on a motion badge (just under the badge, and above the “motion patio” label), is it possible to make that?

Capture

Hi,

I’m trying to style an icon inside a custom:paper-buttons-row and am stuck in the shadow-dom navigation.

The path to the icon I want to style:

MWE of the code (currently not working):

                - type: entities
                  title: Humidificateur
                  entities:
                    - type: 'custom:paper-buttons-row'
                      base_config:
                        style:
                          button:
                            color: lightgrey
                            border-radius: 10%
                      buttons:
                        - icon: 'mdi:air-humidifier'
                          tap_action:
                            action: call-service
                            service: humidifier.toggle
                            service_data:
                              entity_id: humidifier.master_bedroom
                          style:
                            button:
                              color: >-
                                {% if is_state('humidifier.master_bedroom', 'on') %}
                                  var(--accent-color)
                                {% else %}
                                  rgba(255, 255, 255, 0.4)
                                {% endif %}  
                              background-color: rgba(255, 255, 255, 0.4)
                  card_mod:
                    style:  
                      paper-buttons-row$:
                        paper-button:nth-child(1):
                          ha-icon$: |
                            ha-svg-icon {
                              animation: {% if is_state('humidifier.master_bedroom', 'on') %} blink 1s linear infinite alternate {% else %} none {% endif %};
                              color: red !important;
                            }  
                            @keyframes blink {
                              0% { opacity: 0.1; }
                              100% { opacity: 1; }
                            }

The following CSS code works, blinks the whole button (I only want the icon to blink):

                  card_mod:
                    style:  
                      paper-buttons-row$: |
                        paper-button:nth-child(1) {
                          animation: {% if is_state('humidifier.master_bedroom', 'on') %} blink 1s linear infinite alternate {% else %} none {% endif %};
                          color: red !important;
                        }  
                        @keyframes blink {
                           0% { opacity: 0.1; }
                           100% { opacity: 1; }
                        }

What am I missing?

Can Picture_entity card have padding? I’m trying to make this Little Mole smaller but haven’t been succesful so far:

This is what I’m trying:

      - type: picture-entity
        style: |
          ha-card {
          }
          .card-content {
            padding: 10 10 10 10px;
            box-shadow: none;
          }
        entity: script.turn_on_tv_and_kodi
        image: /local/user_images/krtek.png
        name: Krkek?
        tap_action:
          action: call-service
          service: script.turn_on_tv_and_kodi
          service_data: {}
          target: {}
        show_state: false
        show_name: false
        aspect_ratio: '1'

Thanks.

Hi. I’m trying to style color of icon basing on sensor state, but I can’t get it working. So at the beginning I’m trying to do some basing styling, but my icon does not appear anywhere on card.

type: picture-elements
title: Foo
image: local/bar.png
elements:
  - type: icon
    icon: hass:white-balance-sunny
    card-mod:
      style: |
        :host {
          top: 50%;
          left: 50%;
          color: red;
        }

Thank you for your time.

There are errors in your code:

type: picture-elements
title: Foo
image: /local/images/blue.jpg
elements:
  - type: icon
    icon: hass:white-balance-sunny
    style:
      top: 50%
      left: 50%
    card_mod:
      style: |
        :host {
          color: red;
        }
  1. Styling from picture-elements is mixed with styling by card-mod.
  2. The path is /local/....
  3. Keyword card_mod.
1 Like

You’re boss. Thank you!

Probably because you copy-pasted style from another card (facepalm).
The picture-entity card does not seem to have the .card-content element.
Also, wrong value for the padding property was used.
Try using this:

card_mod:
  style: |
    ha-card {
      padding: 20px 20px 20px 20px;
      box-shadow: none;
    }

Anyway, I can’t get it working in more complicated example - when I’m trying to use it in conditional element.

type: picture-elements
title: Foo
image: /local/bar.png
elements:
  - type: icon
    icon: hass:white-balance-sunny
    style:
      top: 10%
      left: 50%
    card_mod:
      style: |
        :host {
          color: {% if is_state('humidifier.zhimi_humidifier_ca1', 'on') %} green {% else %} red {% endif %};
        }
  - type: conditional
    conditions:
      - entity: humidifier.zhimi_humidifier_ca1
        state: 'on'
    elements:      
      - type: conditional
        conditions:
          - entity: switch.humidifier_bedroom_led_on
            state: 'on'
        elements:
          - type: icon
            icon: hass:white-balance-sunny
            style:
              top: 20%
              left: 50%
            card_mod:
              style: |
                :host {
                  color: {% if is_state('humidifier.zhimi_humidifier_ca1', 'on') %} green {% else %} red {% endif %};
                }

image
What’s wrong this time?


@EDIT
I see now on github:

NOTE: card-mod only works on cards that contain a ha-card element. This includes almost every card which can be seen , but not e.g. conditional , entity_filter , vertical-stack , horizontal-stack , grid

So is it possible to make something like that?

Conditional elements - 2 options for styling:

type: vertical-stack
cards:
  - type: entities
    title: Conditional
    entities:
      - entity: input_boolean.test_boolean_2
        name: show
  - type: picture-elements
    card_mod:
      style:
        hui-conditional-element hui-state-label-element:
          $: |
            div {
              color: red;
            }
        .: |
          ha-card {
            height: 80px !important;
          }
    elements:
      - type: state-label
        entity: sensor.cleargrass_1_co2
        style:
          top: 6%
          left: 10%
      - type: conditional
        conditions:
          - entity: input_boolean.test_boolean_2
            state: 'on'
        elements:
          - type: state-label
            entity: sensor.cleargrass_1_co2
            style:
              top: 6%
              left: 30%
    image: /local/images/white.jpg
  - type: picture-elements
    card_mod:
      style: |
        ha-card {
          height: 80px !important;
        }
    elements:
      - type: state-label
        entity: sensor.cleargrass_1_co2
        style:
          top: 6%
          left: 10%
      - type: conditional
        conditions:
          - entity: input_boolean.test_boolean_2
            state: 'on'
        elements:
          - type: state-label
            entity: sensor.cleargrass_2_co2
            style:
              top: 6%
              left: 30%
        card_mod:
          style:
            hui-state-label-element:
              $: |
                div {
                  color: orange;
                }
    image: /local/images/white.jpg

image

Update (20.05.22):
I recommend to use the 1st method.
The 2nd method sometimes does not work:

  1. Open a view with this card.
  2. Set the toggle to OFF. The conditional element is not displayed.
  3. Refresh the page.
  4. Set the toggle to ON. The conditional element is displayed.
  5. The conditional element may not be of orange color - this is a glitch.
  6. Refresh the page.
  7. The conditional element is of orange color.

So, the glitch occurs if the conditional element is not displayed first, then it is displayed w/o the style. The style is applied after refresh only.

Alternatively, on step 6 got to another view and then return to the view - the style is applied.

Also - same problem with a Conditional row inside Entities card. There is an issue on Github.

works perfectly, thanks!

Is there any way to style such dialogs as well? E.g. the more-info-parts like

image

Or to ingest css which has priority over every other stuff?

e.g. the new show more links. I would like to have them in secondery color instead of primary. Currently it is style this way

.header > a, a:visited {
    color: var(--primary-color);
}

But I’m not able to find a point, where and how to change styles in such pop-ups.

Hello, rotating and resizing stop working since last update.
Any idea ?

Thanks a lot !

There is a big mess/change in .11

Everywhere either ha-icon has been renamed in ha-state-icon or sometimes (buttons, …) there is still the ha-icon but an additional ha-state-icon. You have to adopt it accordingly in your style.

What are you talking about exactly, be more specific.
If you are talking about icons inside picture-elements - try to apply the style to the state-badge.
Do some experiments by yourself.

Please see my answer above. ha-icon is not the anchor anymore.

I already told - use state-badge then… HA changes, styling have to be changed too…

?

I don’t have problems. I only said, that I have already answered, where you asked further things.

Now I see it. Yes. Very sad. All icon styling became not working.

It was animated before with this code, but now not

type: entities
entities:
  - entity: switch.tuya_smart_plug
    name: Ventilateur SALON
    icon: mdi:fan
    state_color: true
    style:
      hui-generic-entity-row:
        $:
          state-badge:
            $:
              ha-icon:
                $: |
                  ha-svg-icon {
                    animation: 
                      {% if is_state('switch.tuya_smart_plug', 'on') %} rotation 1s linear infinite {% endif %};
                  }
                  @keyframes rotation {
                    0% {
                      transform: rotate(0deg);
                    }
                    100% {
                      transform: rotate(360deg);
                    }
                  }

Now I see it. Yes. Very sad. All icon styling became not working.

Just rotating and resizing not working, all others still ok.

I will try to find a way, thanks a lot for your help