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

Only card-mod.js.

Everything else is just stuff to create card-mod.js

1 Like

The changes to support modding fold-entity-row are much appreciated! Iā€™m using it like this to dynamically change the icon color for a group and it works great:

      - type: entities
        entities:
          - type: 'custom:fold-entity-row'
            head: group.downstairs_lights
            style: |
              :host {
                --paper-item-icon-color:
                  {% if states('group.downstairs_lights') == 'on' %}
                    red
                  {% else %}
                    green
                  {% endif %}
                  ;
              }
            group_config:
              style: *color

This is the color anchor that I use in a few other places:

color: &color |
  :host {
    --paper-item-icon-color:
      {% if states(config.entity) == 'on' %}
        red
      {% else %}
        green
      {% endif %}
      ;
  }

Hi,

How can I just change the title background?

image

Thx!

@eyalco

 - type: entities
   title: .....
   show_header_toggle: false
   style: |
     .card-header {
       background-color: red;
     }
   entities:
     - entity: ......

Hello @thomasloven, first of all great work for this community, thank you , I have a cenƔrio almost working

This works ok and Iā€™m able to change the background image:

        - type: custom:more-info-card
          entity: light.hallway_tablelight
          title: Luz Mesa
          style: 
              "more-info-controls":
                $:
                  "paper-dialog-scrollable more-info-content":
                    "more-info-light":
                      $:
                        "div div.color_temp":
                          "ha-labeled-slider":
                            $: |
                              ha-paper-slider{
                                    background-image: -webkit-linear-gradient( right, rgb(255,121, 0) 0%, rgb(255,254, 250) 100% );
                              }

image

My question is, at the same level of the ā€œdiv div.color_tempā€ I have ā€œdiv div.brigtnessā€, and I would like to add a style to that element, but

if I do This:

          style: 
              "more-info-controls":
                $:
                  "paper-dialog-scrollable more-info-content":
                    "more-info-light":
                      $: |
                        div div.brightness{
                          background-color: blue !important;
                        }
                        
                        "div div.color_temp":
                          "ha-labeled-slider":
                            $: |
                              ha-paper-slider{
                                    background-image: -webkit-linear-gradient( right, rgb(255,121, 0) 0%, rgb(255,254, 250) 100% );
                              }

It applies the style to ā€œ.brightnessā€, but ignores the drill of ā€œ.color_tempā€

image

If I do This:

          style: 
              "more-info-controls":
                $:
                  "paper-dialog-scrollable more-info-content":
                    "more-info-light":
                      $: |
                        div div.brightness{
                          background-color: blue !important;
                        }
                      $: 
                        "div div.color_temp":
                          "ha-labeled-slider":
                            $: |
                              ha-paper-slider{
                                    background-image: -webkit-linear-gradient( right, rgb(255,121, 0) 0%, rgb(255,254, 250) 100% );
                              }

image

It ignores the style to ā€œ.brightnessā€, drills ā€œ.color_tempā€ and applies the stype to ā€œha-paper-sliderā€ ok.

If I try:

          style: 
              "more-info-controls":
                $:
                  "paper-dialog-scrollable more-info-content":
                    "more-info-light":
                      $: |
                        - div div.brightness{
                            background-color: blue !important;
                          }
                        
                        - "div div.color_temp":
                            "ha-labeled-slider":
                              $: |
                                ha-paper-slider{
                                      background-image: -webkit-linear-gradient( right, rgb(255,121, 0) 0%, rgb(255,254, 250) 100% );
                                }

image

Ignores both.

Can I do this? While drilling into roots, fill styles in the middle.

Thank You

Yes, you can.
To put something inside a root, and also continue drilling, you can use .:, which means ā€œhereā€.

So in your case it would be something like:

"more-info-light":
[...]
$:
  # Put those styles in the shadowRoot element
  .: |
    div div.brightness{
      background-color: blue !important;
    }
  # but also keep going into div div.color_temp...
  "div div.color_temp":
    "ha-labeled-slider":
      $: |
        ha-paper-slider{
          background-image: -webkit-linear-gradient( right, rgb(255,121, 0) 0%, rgb(255,254, 250) 100% );
        }

Is it possible to have the title background part transparent ?

 - type: entities
    title: Date & Time
    show_header_toggle: false
    entities:
      - sensor.date
      - sensor.time
      - sensor.season
      - sun.sun
      - sensor.next_sunrise
      - sensor.next_sunset

try

    style: |
      .card-header {background-color: rgba(0, 0, 0, 0.0);}

Thx, iā€™ve already tried (also transparent) but it doesnā€™t help :frowning:

Try

style: |
  .card-header {
    background-color: var(--primary-background-color);
  }

Seems background now is transparent, so now I need to figure how to remove the shadow

style: |
  .card-header {
    background-color: var(--primary-background-color);
    box-shadow: 0px 0px 0px 3px var(--primary-background-color);
  }
1 Like

Youā€™d have to make the entire card transparent, and then add a background to everything BUT the header.

1 Like

@thomasloven

So now it is transparent :slight_smile: . There are two thins I would like to change:

  1. The top padding is much smaller than the bottom padding (red arrow)
  2. Can I have round corners?

Thx!

@eyalco

- type: entities
  title: .....
  show_header_toggle: false
  style:
    .: |
      ha-card {
        background-color: transparent;
        box-shadow: none;
      }
      .card-content {
        border-radius: 10px;
        padding: 16px;
        background-color: var(--paper-card-background-color);
        box-shadow: var(--ha-card-box-shadow, 0 2px 2px 0 rgba(0, 0, 0, 0.14), 0 1px 5px 0 rgba(0, 0, 0, 0.12), 0 3px 1px -2px rgba(0, 0, 0, 0.2) );
      }
  entities:
    - entity: .....

who can help me out? I canā€™t install the ā€œcard-modā€ I explain to you I followed all the discussions followed the tutorials but nothing, summary I install the ā€œcard-modā€ through HACS then I add the resources as indicated but I get the following errors and the Styles do not apply:

Please show your card configuration too.

      - type: horizontal-stack
        cards:
          - type: custom:canvas-gauge-card
            style: |
              ha-card {
                background-color: transparent; border: none; box-shadow: none;
              }
            entity: sensor.livello_acqua
            card_height: 170
            gauge: 
              type: "radial-gauge"
              title: Livello Acqua
              width: 180
              height: 180
              minValue: 0
              maxValue: 100
              startAngle: 80
              ticksAngle: 200
              valueBox: true
              units: "%"
              majorTicks: ["0", "10", "20", "30", "40", "50", "60", "70", "80", "90", "100"]
              minorTicks: 1
              strokeTicks: true
              highlights: [{"from": 0, "to": 45,"color": "rgba(200, 50, 50, .75)"}]
              colorPlate: "transparent"
              borders: true
              needleType: "arrow"
              needleWidth: 2
              needleCircleSize: 7
              needleCircleOuter: true
              needleCircleInner: false
              animationDuration: 1500
              animationRule: "linear"

this is my configuration, but I want to add that the following error message is present even if I do not insert the style configuration on the card

Hi @thomasloven
Iā€™ve encountered an issue with the card-mod plugin, probably related with your slider-entity-row.

I have added the slider-entity-row as custom-field of a custom button-card in order to control a light. Iā€™m now trying to apply CSS rules to this slider using the card-mod. I figured it out BUT the slider wonā€™t keep the CSS styling - after a few seconds (sounds random) or as soon as Iā€™m shifting the slider, the custom CSS style disappears.

I have noticed that when I try to inspect the slider element with the Chrome (or Safari) dev tools, after a few seconds, I lost the focus on the HTML element being inspected.

It looks like a refresh, but the page is not refreshing at allā€¦

Hopefully Iā€™m clear, please let me know what you need from me to reproduce it.
Thanks

edit. Making some troubleshooting - seems like it occurs only when embedded into a custom button-card (as custom-field). Is there any chance, you have an idea of what makes this happen ? Thanks again !

edit 2. I have opened a bug report on the button-card github (https://github.com/custom-cards/button-card/issues/268) as Iā€™m pretty sure that the problem comes from it - but hopefully youā€™ll have a way to prevent the bug to occur from your side too.