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

hey Ildar, this is super nice.

can you help me out find the right path and margin settings for the aria-selected='true' tab, so we can do what we can in the main HA menubar:

      paper-tab[aria-selected=true] {
        background-color: rgba(var(--primary),0.3);
        --mdc-icon-size: {{states('input_number.active_icon_size')}}px;
      }

especially concerned for the size, though background would also be a nicety

active icon size:

SchermĀ­afbeelding 2023-02-21 om 13.44.47

I did find this to work:

card_mod:
  style:
    tabbed-card $:
      mwc-tab:
        $: |
          .mdc-tab {
            min-width: 60px;
          }
          .mdc-tab--active {
            --mdc-icon-size: {{states('input_number.active_icon_size')}}px;
          }

showing:

but as you can see, the icon dropsā€¦

btw, I am using max 5 icons, and experimented with your mod. Seems we dont need the padding mod? and thereā€™s nt much difference in my config when using the various px settings:

        $: |
          .mdc-tab {
            min-width: 70px;
          }

alone works fine, and appears to be the max for 5 icons, but I can set it to any number below that too? does not make the icons go closer, like in your mod, even with the padding set to 0px. With or without !important. hmm.

background colors for the tabs:

type: custom:mod-card
card_mod:
  style:
    tabbed-card $:
      mwc-tab:
        $: |
          .mdc-tab {
            min-width: 70px;
            background: var(--primary-color);
          }
          .mdc-tab--active {
             background: var(--text-color-off);
          }

or if you want them all:

     .: |
       :host {
         background: green;
       }

and now we see what the horizontal padding does:

type: custom:mod-card
card_mod:
  style:
    tabbed-card $:
      mwc-tab:
        $: |
          .mdc-tab {
            min-width: 40px;
            background: var(--primary-color);
          }
    .: |

      tabbed-card {
        --mdc-tab-horizontal-padding: 0px;
      }
card:
  type: custom:tabbed-card
  attributes:
    minWidth: true
    isMinWidthIndicator: true
    isFadingIndicator: true

so there is still space between the tabs?

lastly:
how to get to the

        .mdc-tab-indicator .mdc-tab-indicator__content--underline {
          border-color: black;
        }

?

that would be:

type: custom:mod-card
card_mod:
  style:
    tabbed-card $:
      mwc-tab:
        $:
          mwc-tab-indicator $: |
           .mdc-tab-indicator__content--underline {
              border-color: black !important;
            }

but, how to combine that with:

type: custom:mod-card
card_mod:
  style:
    tabbed-card $:
      mwc-tab:
        $: |
          .mdc-tab {
            min-width: 40px;
            background: var(--primary-color);
          }
          .mdc-tab--active {
             background: var(--text-color-off);
          }

is this the best way?

type: custom:mod-card
card_mod:
  style:
    tabbed-card $:
      mwc-tab:
        $:
          mwc-tab-indicator $: |
           .mdc-tab-indicator__content--underline {
              border-color: red !important;
            }

          .: |
            .mdc-tab {
              min-width: 40px;
              background: var(--primary-color);
            }
            .mdc-tab--active {
               background: var(--text-color-off);
            }

Probably, this happens due to ā€œdisplay: inlineā€ property.
The element is not vertically aligned, it grows to ā€œdownā€ direction.

Does not work w/o !important, check this:

    card_mod:
      style:
        tabbed-card $:
          mwc-tab:
            $:
              mwc-tab-indicator $: |
                .mdc-tab-indicator__content--underline {
                  border-color: red !important;
                }
              .: |
                .mdc-tab {
                  min-width: 40px !important;
                  background: yellow !important;
                }
                .mdc-tab--active {
                  background: lightgreen !important;
                }

image

hmm, how strange, in my desktop browser (Safari Mac) and the iOS App, !important is only required on the tab-indicator border color.

because of your remark, I just checked Firefox and Chrome, and indeed, those browsers need the !important on the other settings tooā€¦

remarkable.

the order and hierarchy was right though, and that was my main point for asking.
thanks for confirming

I see, but, not really.

I tried to use:

            .mdc-tab--active {
              --mdc-icon-size: {{states('input_number.active_icon_size')}}px;
              display: flex !important;
              justify-content: center !important;
              align-items:  center !important;
            }

but nothing happens.
yet, if I check higher in the inspector most of the properties are centered already?

SchermĀ­afbeelding 2023-02-22 om 08.49.52

though the padding is not.

the only way I can move the icon is changing the padding, but I cant make it move upwards:

              padding-bottom: 24px !important;

and setting

              padding: 0px !important;

moves it almost out of sight downwardsā€¦

also tested these options: How to Center An Image Horizontally and Vertically in CSSā€¦

suppose it can be done, do we need another element, maybe the icon itself, and not the tab?

amazingly enough, the

            .mdc-tab--active {
              --mdc-icon-size: {{states('input_number.active_icon_size')}}px;
            }

does Not require !important in Chrome or Firefoxā€¦

Update

think I found the correct property:

display: contents

positions the icon properly:

now how to get thereā€¦

seems like this :wink:

type: custom:mod-card
card_mod:
  style:
    tabbed-card $:
      mwc-tab:
        $:
          mwc-tab-indicator $: |
           .mdc-tab-indicator__content--underline {
              border-color: var(--text-color-off) !important;
            }

          .: |
            .mdc-tab {
              min-width: 40px !important;;
              background: var(--primary-color) !important;
            }
            .material-icons {
              display: contents !important;
            }
            .mdc-tab--active {
              --mdc-icon-size: {{states('input_number.active_icon_size')}}px;
              /*background: var(--text-color-off) !important;*/
            }

    .: |

      tabbed-card {
        --mdc-tab-horizontal-padding: 0px;
      }

itā€™s starting to be a huge mod, but it works really well.

NB:
documentation mentions --mdc-theme-secondary: for the indicator icon (when set) so I gave

    --mdc-theme-secondary: var(--text-color-off)

a try. This however seems to be not useful, and further inspection shows the indicator icon = ā€˜ā€™ā€¦

setting that attribute on either the main config or a tab, does not do anything either. no indicator icon at all. So I probably am missing the point here, or we have a bug

we houd however be able to set:

  styles:
    --mdc-tab-horizontal-padding: 0px;

and not have to card_mod that with:

     .: |
       tabbed-card {
         --mdc-tab-horizontal-padding: 0px;
       }

I want to remove three icons from the ā€œthermostatā€ card.
triple dots
heat/cool
cool

Screenshot 2023-02-22 at 09.12.11

Starting with dots in the corner, I have the following:

type: thermostat
entity: climate.radiator_01_thermostat
name: ' '
card_mod:
  style: |
    ha-icon-button$: |
      mwc-icon-button {
        display: none;
      }

Could someone please give me some pointers on how to proceed?

Thank you

            card_mod:
              style: 
                ha-icon-button$: |
                  mwc-icon-button {
                    display: none;
                  }            
                .: |
                  div#modes ha-icon-button:nth-child(1) {
                    display: none;

So for the first there was a wrong | and for the rest see the example and count the item to hide.

How to put mdi:icon to state-badge? I read above post but this not work for me.

          - type: conditional
            conditions:
              - entity: input_boolean.menu_parter
                state: "off"
                card_mod:
                  style: |
                    :host {
                      --card-mod-icon: mdi:bed;
                    }
            elements:
              - entity: light.sufit_salon
                style:
                  top: 65%
                  left: 52%
                  color: transparent
                  transform: scale(0.7,0.7)
                tap_action: !include FloorPlan3D/popup/swiatlo_salon405.yaml
                type: state-badge

or

          - type: conditional
            conditions:
              - entity: input_boolean.menu_parter
                state: "off"
            elements:
              - entity: light.sufit_salon
                style:
                  top: 65%
                  left: 52%
                  color: transparent
                  transform: scale(0.7,0.7)
                card_mod:
                  style: |
                    :host {
                      --card-mod-icon: mdi:bed;
                    }
                tap_action: !include FloorPlan3D/popup/swiatlo_salon405.yaml
                type: state-badge

where to put:

                card_mod:
                  style: |
                    :host {
                      --card-mod-icon: mdi:bed;
                    }

Hello, I am attempting to use card-mod to change the background picture every 10 seconds, But I cant seem to get the scripts to function. Is there a better way to do this? Here is my current code:

type: custom:flipclock-card
time:
  face: TwelveHourClock
card_mod:
  style: |
    ha-card {
      width: 1279px;
      height: 393px !important;
      --card-background-color: #b1aaab;
      background: url(http://picsum.photos/1280/400?random=${timestamp});
      box-shadow: inset 0 0 0 2000px rgb(56 43 1 / 44%);
    }
    .fc-date {
      font-size: 45px !important;
      height: 55px !important;
      display: none;
    }
    .flip-clock {
      font-size: 50px;
    }
    .flip-clock-label {
      display: none;
    }
    .fc-now {
      opacity: 90%
    }
    .background {
      background-repeat: no-repeat;
      background-size: cover;
      background-position: center;
      height: 100%;
      width: 100%;
    }
  scripts: |
    function updateBackground() {
      console.log('updateBackground');
      var timestamp = Date.now();
      var backgroundImage = `url(http://picsum.photos/1280/400?random=${timestamp})`;
      var style = `
        ha-card {
          background: ${backgroundImage};
        }
      `;
      console.log('style:', style);
      var card = document.querySelector("flipclock-card");
      console.log('card:', card);
      if (card) {
        card.card_mod_style = style;
        console.log('card_mod_style:', card.card_mod_style);
      } else {
        console.error('flipclock-card element not found');
      }
    }

    updateBackground();
    setInterval(() => {
      updateBackground();
      console.log('Interval set');
    }, 10000);
    console.log('Initial Interval set');

Hi all,

It looks like a simple question but I cannot find the working answer. Could you please advise me how to change the header font size (make it smaller) in following vertical stack and how to save some space between header and button cards?

Thank you.

image

type: vertical-stack
title: Scene
cards:
  - type: horizontal-stack
    cards:
      - type: custom:button-card
        entity: switch.sonoff_1120a09bd4
        name: Lamps
        size: 40%
        state:
          - value: 'on'
            color: rgb(223, 218, 0)
            icon: mdi:lamps
            styles:
              card:
                - background-color: ivory
                - box-shadow: 0px 0px 20px 2px rgb(240, 194, 9)
          - value: 'off'
            icon: mdi:lamps-outline
        styles:
          card:
            - height: 80px
            - border-radius: 10%
            - padding: 10%
            - font-size: 10px
      - type: custom:button-card
        entity: switch.sonoff_1120a09345
        name: TV light
        size: 40%
        state:
          - value: 'on'
            color: rgb(223, 218, 0)
            icon: mdi:television
            styles:
              card:
                - background-color: ivory
                - box-shadow: 0px 0px 20px 2px rgb(240, 194, 9)
          - value: 'off'
            icon: mdi:television-off
        styles:
          card:
            - height: 80px
            - border-radius: 10%
            - padding: 10%
            - font-size: 10px
      - type: custom:button-card
        entity: switch.sonoff_1120b0389f
        name: Garden lights
        size: 40%
        state:
          - value: 'on'
            color: rgb(223, 218, 0)
            icon: mdi:alarm-light-outline
            styles:
              card:
                - background-color: ivory
                - box-shadow: 0px 0px 20px 2px rgb(240, 194, 9)
          - value: 'off'
            icon: mdi:alarm-light-off-outline
        styles:
          card:
            - height: 80px
            - border-radius: 10%
            - padding: 10%
            - font-size: 10px
      - type: custom:button-card
        entity: switch.sonoff_11211a38ac
        name: Kitchen lights
        size: 40%
        state:
          - value: 'on'
            color: rgb(223, 218, 0)
            icon: mdi:track-light
            styles:
              card:
                - background-color: ivory
                - box-shadow: 0px 0px 20px 2px rgb(240, 194, 9)
          - value: 'off'
            icon: mdi:track-light-off
        styles:
          card:
            - height: 80px
            - border-radius: 10%
            - padding: 10%
            - font-size: 10px
  - type: horizontal-stack
    cards:
      - type: custom:button-card
        name: Gate
        entity: binary_sensor.gate_opening_detector
        color: rgb(64, 114, 164)
        size: 40%
        state:
          - value: 'on'
            color: rgb(255, 124, 128)
            icon: mdi:gate-open
            styles:
              card:
                - background-color: lightpink
                - box-shadow: 0px 0px 20px 2px rgb(255, 124, 128)
          - value: 'off'
        icon: mdi:gate
        tap_action:
          action: call-service
          service: script.toggle
          service_data:
            entity_id: script.gate_open_close
        styles:
          card:
            - '--mdc-ripple-color': green
            - '--mdc-ripple-press-opacity': 0.7
            - height: 80px
            - border-radius: 10%
            - padding: 10%
            - font-size: 10px
      - type: custom:button-card
        name: Gate entrance
        icon: mdi:gate-arrow-right
        color: rgb(64, 114, 164)
        size: 40%
        tap_action:
          action: call-service
          service: script.toggle
          service_data:
            entity_id: script.gate_entrance
        styles:
          card:
            - '--mdc-ripple-color': green
            - '--mdc-ripple-press-opacity': 0.7
            - height: 80px
            - border-radius: 10%
            - padding: 10%
            - font-size: 10px
      - type: custom:button-card
        name: Garage door (W)
        entity: binary_sensor.garage_door_w_opening_detector
        color: rgb(64, 114, 164)
        size: 40%
        state:
          - value: 'on'
            color: rgb(255, 124, 128)
            icon: mdi:garage-open-variant
            styles:
              card:
                - background-color: lightpink
                - box-shadow: 0px 0px 20px 2px rgb(255, 124, 128)
          - value: 'off'
            icon: mdi:garage-variant
        tap_action:
          action: call-service
          service: script.toggle
          service_data:
            entity_id: script.open_garage_door_w
        styles:
          card:
            - '--mdc-ripple-color': green
            - '--mdc-ripple-press-opacity': 0.7
            - height: 80px
            - border-radius: 10%
            - padding: 10%
            - font-size: 10px
      - type: custom:button-card
        name: Garage door (E)
        entity: binary_sensor.garage_door_e_opening_detector
        color: rgb(64, 114, 164)
        size: 40%
        state:
          - value: 'on'
            color: rgb(255, 124, 128)
            icon: mdi:garage-open-variant
            styles:
              card:
                - background-color: lightpink
                - box-shadow: 0px 0px 20px 2px rgb(255, 124, 128)
          - value: 'off'
            icon: mdi:garage-variant
        tap_action:
          action: call-service
          service: script.toggle
          service_data:
            entity_id: script.open_garage_door_e
        styles:
          card:
            - '--mdc-ripple-color': green
            - '--mdc-ripple-press-opacity': 0.7
            - height: 80px
            - border-radius: 10%
            - padding: 10%
            - font-size: 10px

Hi there,

I am new in HA and I try to modify a mushroom-template card. Actually it looks like this:


Now I wanted to modify the second line of the grey text in that way, that it shlould have a different color but I donĀ“t know, if this is possible.

Here is my code for the respective card.

type: custom:mushroom-template-card
primary: 'šŸ”¦ Gartenbeleuchtung:'
multiline_secondary: true
secondary: >-
  {%- set days = ["Sonntag", "Montag", "Dienstag", "Mittwoch", "Donnestag",
  "Freitag", "Samstag"] %} {%- set months = ["Januar", "Februar", "MƤrz",
  "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November",
  "Dezember"] %} {%-set su = state_attr('sensor.su_gartenlicht',
  'tomorrow').timestamp() %} {%-set wd_su = days[ su | timestamp_custom("%w") |
  int] %} {%-set mo_su = months [( (su )| timestamp_custom("%m") | int)-1]%}

  nƤchste Einschaltzeit:

  {{ su | timestamp_custom(wd_su~ ", %d. " +mo_su~" %Y um %H:%M Uhr")}}
icon: ''
card_mod:
  style: |
    ha-card {

       --card-primary-font-size: 1.8rem;
       --card-primary-font-weight: normal;
       --card-secondary-font-size: 1.0rem;
       --card-primary-line-height: 2.0;
       --card-secondary-line-height: 1.5;
       --primary-text-color: #E0E0E0;
       --secondary-text-color: #808080;
         font-family:'roboto';
         font-weight: normal;
         border: none;
         box-shadow: none;
         margin-top: 0.0rem;
         ## background:none;
    }

This part represents the second line:
{{ su | timestamp_custom(wd_su~ ", %d. " +mo_su~" %Y um %H:%M Uhr")}}

and btw.i am not good at coding, so this all looks quite bumpy. Maybe someone has a better idea to build this card :slight_smile:

Spartacus

For some reason after upgrading to card-mod 3.2.0 cardmod isnā€™t working anymore on my ā€œcustom:vertical-stack-in-cardā€. Any idea what iā€™m missing my ā€œ.card-headerā€ class isnā€™t working anymore?

- type: custom:vertical-stack-in-card
        title: Buiten
        cards:
          - type: horizontal-stack
            cards:
              - type: custom:mini-graph-card
                entities:
                  - sensor.tempbuiten_temperature
                name: Temp - Actueel
                line_width: 2
                hours_to_show: 24
                font_size: 200
                font_size_header: 18
                decimals: 1
              - type: vertical-stack
                cards:
                  - type: statistic
                    entity: sensor.tempbuiten_temperature
                    period:
                      calendar:
                        period: day
                    stat_type: min
                    name: Temp - Min (24h)
                    style: |
                      .info .value {
                        font-size: 35px;
                      }
                      .info .measurement {
                        font-size: 35px;
                      }
                      .header .name {
                        font-size: 20px;
                      }
                  - type: statistic
                    entity: sensor.tempbuiten_temperature
                    period:
                      calendar:
                        period: day
                    stat_type: max
                    name: Temp - Max (24h)
                    style: |
                      .info .value {
                        font-size: 35px;
                      }
                      .info .measurement {
                        font-size: 35px;
                      }
                      .header .name {
                        font-size: 20px;
                      }
              - type: custom:mini-graph-card
                entities:
                  - sensor.tempbuiten_humidity
                name: Luchtvochtigheid
                line_width: 2
                hours_to_show: 24
                font_size: 200
                font_size_header: 18
                decimals: 1
        card_mod:
          style: |
            .card-header {
              padding-top: 2px;
              padding-bottom: 2px;
              font-size: 33px;
            }

card-header is now in the shadow root or the other way round not manipulated to another place from card_mod anymore.

So you have to dig one $ deeper. Examples and topic is somewhere above in this thread around update time which intrpoduced this change.

problem fix :stuck_out_tongue: remember to use custom:badge-card not state-badgeā€¦

anyway ā€¦ how to add this:

                card_mod:
                  style:
                    ha-state-label-badge:
                      $:
                        ha-label-badge:
                          $: |
                            .badge-container .label-badge .label span {
                              border-style: solid;
                              border-color: transparent;
                              color: transparent;
                              background-color: transparent;
                            }
                            .badge-container .title {
                              color: transparent;
                            }
                        .: |
                          ha-label-badge {
                            --label-badge-background-color: gray;
                            --label-badge-text-color: white;
                            --label-badge-red: black;
                          }

to this

      - entity: sensor.cleargrass_1_co2
        icon: mdi:home  ###creates a placeholder
        card_mod:
          style: |
            :host {
              {% if states(config.entity) | int > 600 %}
              --card-mod-icon: mdi:fire;
              {% else %}
              --card-mod-icon: mdi:leaf;
              {% endif %}
            }

I have been looking for the error in my code for days now.
I want to change the padding in this pop-up card but no matter what code I try it has no effect on the card.
I am afraid I have lost my way. Can someone please tell me where my error lies?
Thank you very much.

Code:

  - type: image
    entity: cover.velux_window_roof_window
    state_image:
      open: /local/ui/floorplan/lite-on.png
      closed: /local/ui/floorplan/lite-off.png
      half-open: /local/ui/floorplan/lite-unavailable.png
    style:
      top: 5%
      left: 50.5%
      width: 2%
    tap_action:
      action: fire-dom-event
      browser_mod:
        service: browser_mod.popup
        data:
          title: roof-window
          content:
            type: custom:shutter-row
            entity: cover.velux_window_roof_window
            name: Garden
            invert_position: false
            state_color: true
            card_mod:
              style: |
                ha-card { border: yes; padding: 100px; }

Picture of the DOM Navigation
image

Hi guys,
could someone please kindly help me out with the following alarm card

Iā€™m trying to reduce the padding from above and below to reduce the card size. Iā€™ve edited it in the web console and have the required affect


Yet when i save the yaml code and reload my page it ignores it and reverts back

Could you please tell me what Iā€™m doing wrong

Maybe add !important ?
padding: 10px 1px !important;
padding-bottom: 1px !important;

1 Like

thank you for the help,
I couldnā€™t get this to work, but I was able to achieve it with the below

style: |
  ha-card.type-custom-alarmo-card {
    padding-bottom: 1px;
    }
  div.header {
    padding: 10px
1 Like

Iā€™m trying to change the padding for a vertical stack card but i canĀ“t get it to work, any ides?

type: vertical-stack
title: Kitchen
card_mod:
  style: |
    .card-header {
        padding: 6px 16px 2px !important;
    }
cards:
  - type: custom:mushroom-chips-card
    chips:
      - type: entity
        entity: sensor.temperature_77
      - type: entity
        entity: sensor.humidity_76
      - type: entity
        entity: sensor.lightlevel_48