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

So first of all, thanks! Owing to a lack of necessity, and an assumption itā€™d be completely over my head, I havenā€™t really explored editing Lovelace resources like this. However, I found this bit of code in the js and it does look very straightforward.

Unfortunately though, making the change across the whole config isnā€™t ideal. Iā€™d prefer the chevron icon in most instances since itā€™s quite minimal, but I want to use fold-entity-row in conjunction with mini media player, and MMP also uses the chevron icon for the source select menu. Having both is a little confusing, so I wanted to use mdi:minus/plus-circle-outline for MMPs (and also for select fold rows that are bigger/more important).

I believe any changes I make to the resource also wonā€™t survive an update via HACS, right?

1 Like

wouldnā€™t know about the HACS specifics sorry.

And the MMP indeed looks nice!

Guess youā€™re right not wanting to mod the resource, and try to card-mod the icon. Sometimes its indeed not very obvious why things happen or not. In that case you could raise an issue in the Repo for the card, Thomas wrote both card-mod and fold-entity-row, so thats handy :wink: or try and ask him in #frontend Discord channel, heā€™s mostly there.

Can anyone suggest what would be the issue with the icon rotation in the picture-elements component below? This used to work fine, and at some point it stopped. Iā€™ve spent the last hour looking through this thread, and only one other person had something they confirmed worked, but it does not work for me.

       cards:
          - type: picture-elements
            image: /local/floorplan.jpg
            style: |
              ha-card {
                --cover_master_bedroom_color: {% if is_state('input_select.cover_master_bedroom','Closed') %} 4d4d4d {% else %} gold {% endif %};
                --cover_living_room_color: {% if is_state('input_select.cover_living_room','Closed') %} 4d4d4d {% else %} gold {% endif %};
                --cover_bedroom_3_color: {% if is_state('input_select.cover_bedroom_3','Closed') %} #4d4d4d {% else %} gold {% endif %};
                --cover_study_color: {% if is_state('input_select.cover_study','Closed') %} 4d4d4d {% else %} gold {% endif %};
              }
            elements:
....
....
              - type: state-icon
                tap_action:
                  action: more-info
                entity: fan.bedroom_3_fan
                style:
                  top: 15%
                  left: 18%
                  --paper-item-icon-color: white
                card_mod:
                  style: |
                    state-badge:
                      $:
                        ha-icon:
                          $: |
                            ha-svg-icon {
                              {% if is_state('fan.study_fan', 'on') %}
                                animation: rotation 1s linear infinite;
                              {% endif %}
                            }
                            @keyframes rotation {
                              0% {
                                transform: rotate(0deg);
                              }
                              100% {
                                transform: rotate(360deg);
                              }
                            }

Regardless of whether the condition is set on the rotation (being on), it doesnt rotate on or off.

Is there a way to place a image as background or add text on to the pagination bullets on the right?

          - type: custom:mod-card
            style: 
              swipe-card:
                $: |
                  .swiper-pagination {
                     top: 0vw;
                    }
                  .swiper-pagination-bullets .swiper-pagination-bullet {
                     margin-top: 6px !important;
                    }
                  .swiper-container {
                     overflow: visible !important;
                    }
                  .swiper-container .swiper-button-next {
                     display: none;
                    }
                  .swiper-container .swiper-button-next::after {
                     display: none;
                    }
                  .swiper-container .swiper-button-prev {
                     display: none;
                    }
                  .swiper-container .swiper-button-prev::after {
                     display: none;
                    }
                  .swiper-pagination-bullets span {
                     display: block !important;
                     width: 12%;
                     height: 17%;
                     border-radius: 5%;
                     opacity: 1;
                     background-size: cover;
                    }
                  .swiper-container-horizontal .swiper-pagination-bullets {
                     left: 75vw !important;
                    }                 
            card:
              type: custom:swipe-card
              parameters:
                roundLengths: true
                centeredSlides: true
                effect: coverflow
                preventClicks: true
                init: true
                loop: true
                speed: 650
                spaceBetween: 500
                threshold: 5
                coverflowEffect:
                  rotate: 80
                  depth: 200
                pagination:
                  type: bullets
                  clickable: true
              cards:
                - !include /config/include/swiper_1.yaml
                - !include /config/include/swiper_2.yaml

1st post ā†’ link at the bottom ā†’ post about picture-elements.

Hi @Ildar_Gabdullin I was looking for a way to hide/ make the underline completely transparent (not visible). Is there a way to do this? Actually I wanted to try it with the coloring method described in this post, but it seems I can only get it applied to labels and not not for underline (so I couldnā€™t try to set it transparent this way).

Thanks got there with that,

              - type: state-icon
                tap_action:
                  action: more-info
                entity: fan.bedroom_3_fan
                style:
                  top: 15%
                  left: 18%
                  --paper-item-icon-color: white
                card_mod:
                  style: |
                    state-badge {
                      {% if is_state('fan.bedroom_3_fan', 'on') %}
                        animation: rotation 1s linear infinite;
                      {% endif %}
                    }
                    @keyframes rotation {
                      0% {
                        transform: rotate(0deg);
                      }
                      100% {
                        transform: rotate(360deg);
                      }
                    }

There is a method of coloring the underline only, check the post you answered.

I tried that before I asked and it doesnā€™t work for me. Is it not possible that some recent HA change requires a different approach?

Everything is possible, of course. Then other ways should be found.

Is it possible to box all cards ā€œinsideā€ ā€œthe card modā€ instead of doing it this way for each and every cards? See below;

  - title: Tester2
    path: tester2
    layout:
      width: 300
      max_cols: 2
    type: custom:masonry-layout
    badges: []
    icon: mdi:shield-search
    cards:
# Cards start
# I want them in a horizontal stack
    - type: horizontal-stack
      cards:
# Here the actual cards start 
      - type: custom:mod-card
        card:
          type: custom:button-card
          template: chip_custom_navigation
          variables:
            ulm_card_navigate_path: /lovelace-minimalist/tele_start
            ulm_card_navigate_title: ""
            ulm_card_navigate_icon: mdi:sigma
        card_mod:
          style: |
            button-card {
              position: fixed;
              bottom:0;
            }
# Next card
      - type: custom:mod-card
        card:
          type: custom:button-card
          template: chip_custom_navigation
          variables:
            ulm_card_navigate_path: /lovelace-minimalist/tele_media
            ulm_card_navigate_title: ""
            ulm_card_navigate_icon: mdi:youtube-tv
        card_mod:
          style: |
            button-card {
              position: fixed;
              bottom:0;
            }
# Next card
      - type: custom:mod-card
        card:
          type: custom:button-card
          template: chip_custom_navigation
          variables:
            ulm_card_navigate_path: /lovelace-minimalist/tele_temp
            ulm_card_navigate_title: Temp
            ulm_card_navigate_icon: mdi:temperature-celsius
        card_mod:
          style: |
            button-card {
              position: fixed;
              bottom:0;
            }
# Next card
      - type: custom:mod-card
        card:
          type: custom:button-card
          template: chip_custom_navigation
          variables:
            ulm_card_navigate_path: /lovelace-minimalist/tele_markplan
            ulm_card_navigate_title: ""
            ulm_card_navigate_icon: mdi:home-floor-1 
        card_mod:
          style: |
            button-card {
              position: fixed;
              bottom:0;
            }
# Next card
      - type: custom:mod-card
        card:
          type: custom:button-card
          template: chip_custom_navigation
          variables:
            ulm_card_navigate_path: /lovelace-minimalist/tele_ovanvaning
            ulm_card_navigate_title: ""
            ulm_card_navigate_icon: mdi:home-floor-2 
        card_mod:
          style: |
            button-card {
              position: fixed;
              bottom:0;
            }
# End cards

So, here is the solution

  - title: Tester2
    path: tester2
    layout:
      width: 300
      max_cols: 2
    type: custom:masonry-layout
    badges: []
    icon: mdi:shield-search
    cards:
      - type: custom:mod-card
        card:
          type: "horizontal-stack"
          cards:
            - type: custom:button-card
              template: chip_custom_navigation
              variables:
                ulm_card_navigate_path: /lovelace-minimalist/tele_start
                ulm_card_navigate_title: ""
                ulm_card_navigate_icon: mdi:sigma
            - type: custom:button-card
              template: chip_custom_navigation
              variables:
                ulm_card_navigate_path: /lovelace-minimalist/tele_media
                ulm_card_navigate_title: ""
                ulm_card_navigate_icon: mdi:youtube-tv
            - type: custom:button-card
              template: chip_custom_navigation
              variables:
               ulm_card_navigate_path: /lovelace-minimalist/tele_temp
               ulm_card_navigate_title: Temp
               ulm_card_navigate_icon: mdi:temperature-celsius
            - type: custom:button-card
              template: chip_custom_navigation
              variables:
                ulm_card_navigate_path: /lovelace-minimalist/tele_markplan
                ulm_card_navigate_title: ""
                ulm_card_navigate_icon: mdi:home-floor-1 
            - type: custom:button-card
              template: chip_custom_navigation
              variables:
                ulm_card_navigate_path: /lovelace-minimalist/tele_ovanvaning
                ulm_card_navigate_title: ""
                ulm_card_navigate_icon: mdi:home-floor-2 
        card_mod:
          style: |
            ha-card {
              position: fixed;
              bottom:0;
            }

Hi all,
First of all: @Ildar_Gabdullin, great job on the support and documentation!

I have a question about the Chip cards. Since they are buttons they donā€™t facilitate the use of show_state. Is there a way to use card-mod to show the state instead of the name of the entity?

Without test: Set name as blank and then css ::before or ::after with template.

1 Like

Thanks for the quick reply!
Iā€™m afraid I need a little bit more help though. The last time I used CSS was a long time ago and I always copied and pasted code which I them tweaked to get what I wanted.
I tried the same using the post Ildar made (šŸ”¹ Card-mod - Add css styles to any lovelace card - #1729 by Ildar_Gabdullin) but Iā€™m not getting the result yet.
Could you give me a little push in the right direction?

Here is the code I ended up with:

type: vertical-stack
cards:
  - type: entities
    entities:
      - type: buttons
        entities:
          - entity: sensor.elektra_kosten_totaal
            icon: mdi:lightning-bolt
            show_name: false
            show_icon: true
            card_mod:
              style: |
                .text-content::before {
                  content: "{{states(sensor.elektra_kosten_totaal)}}";
                }

Which results in:
afbeelding

Cannot say about other stuff but here is an error - entity_id without quotes.
Also, not sure about a presence of ā€œtext-contentā€ since you have ā€œshow_name: falseā€. Check it by yourself just in case.

Also, all elementsā€™ names should be accordingly to a real DOM structure. I mean - the ā€œtext-contentā€ element should really exist.

Alas, adding the quotes didnā€™t result in the state being displayed.
I made a screenshot of the dev tools view. The element that results in showing the text is called: mdc-chip__text.
Would it be possible to brute force the content of this field?

Hello. Healthy places of style.
I intend to use several gauges side by side I canā€™t match them. It is a canvas-gauge-card canvas-gauges.com. Iā€™m already fighting it the next day. Is there any advice?

how oddā€¦

if I use this decluttering template:

card:
  type: custom:auto-entities
  card:
    type: entities
#    title: '[[area_name]]'
    show_header_toggle: false
  entities:
    - type: custom:hui-element
      card_type: area
      card_mod:
        style:
          div#container: |
            hui-image {
              box-shadow: none;
              margin: -16px -16px 0x -16px;
            }
      area: '[[area_id]]'
  filter:
    template: >
      {{'[[area_id]]'|area_entities}}
#  sort:
#    method: domain

with the bottom sort, the Area card gets added at the bottom, and I can simply mod the margins.

{
              box-shadow: none;
              margin: 0px -16px -16x -16px;
            }

and the Area card is spread to touch the card bordered perfectly.

However, if I use the above config, drop the sort, and let the Area card be listed atop (what I want) I can not mod the marginsā€¦

tried to do this:

      card_mod:
        style:
          div#container: |
            hui-image {
              box-shadow: none;
              margin: -16px -16px 0x -16px;
            }

which I think is what inspector tells me to do, but no effect at all.

using

      card_mod:
        style: |
          ha-card {
            box-shadow: none;
            margin: -16px -16px 0x -16px;
            }

at least takes out the box-shadow, so Ill leave that in . Now how to spread the image to use -16px 16px 0px -16px?

ofc, I can make Ildar happy and use stack-in-card (and re-instate the sort!) :

card:
  type: custom:stack-in-card
  cards:
    - type: area
#      card_mod:
#        style: |
#          ha-card {
#            box-shadow: none;
#            margin: -16px -16px 0x -16px;
#            }
      area: '[[area_id]]'

    - type: custom:auto-entities
      card:
        type: entities
    #    title: '[[area_name]]'
        show_header_toggle: false
      filter:
        template: >
          {{'[[area_id]]'|area_entities}}
      sort:
        method: domain
        reverse: true

but thats a bit besides the challenge :wink:

Also that wont work when I uses them in folds:

this is the best overall config, only wish I could margin the items in the foldsā€¦the div#items doesnt do anythingā€¦

    entities:
      - type: custom:decluttering-card
        template: areas
        variables:
          - area_name: Keuken
          - area_id: kitchen

      - type: custom:decluttering-card
        template: areas
        variables:
          - area_name: Library
          - area_id: library

with:

card:
  type: custom:fold-entity-row
  head:
    type: section
    label: '[[area_name]]'
#  card_mod:
#    style: |
#      div#items {
#        margin: 0px -16px 0px -16px;
#      }
  padding: 0
  entities:

    - type: custom:hui-element
      card_type: area
      card_mod:
        style: |
          ha-card {
            box-shadow: none;
          }
      area: '[[area_id]]'

    - type: custom:auto-entities
      card:
        type: entities
        card_mod:
          style: |
            ha-card {
              box-shadow: none;
            }
        show_header_toggle: false
      filter:
        template: >
          {{'[[area_id]]'|area_entities}}
      sort:
        method: domain
        reverse: true

I have a requirement that needs card-mod to set the height of image elements in a picture-elements card. There is a background image with a few mask images (full width but 1px high) that are overlaid on top. Here is a drawing of what I am trying to do:

By setting the height and top location of the masks, any level in any position can be show.

The problem is that I canā€™t get the height of the image elements set as per my yaml below.

    - type: picture-elements
      image: /local/background_image.png
      elements:
         - type: image
           image: /local/mask1.png
           card_mod:
             style: | 
               :host {
                  height: [templated from sensor 1 value]
                }
         - type: image
           image: /local/mask2.png
           card_mod:
             style: | 
               :host {
                  height: [templated from sensor 2 value]
                }

What I end up with is the main image with the two masks in the correct positions, but the heights are still 1px.

I suspect it is some funky CSS issue where I am not styling the correct element, but I simply do not know enough to fix this.

Can anybody help me with setting the height of these elements?